Skip to content

Instantly share code, notes, and snippets.

@bdougie
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save bdougie/a0ad352f508203e30cc4 to your computer and use it in GitHub Desktop.

Select an option

Save bdougie/a0ad352f508203e30cc4 to your computer and use it in GitHub Desktop.
class Feedback
def self.dispatch_surveys!
upcoming_enrollments.each do |enrollment|
Rails.logger.info "dispatching feedback request to #{enrollment.user.name}"
enrollment.chain.feedbacks.create!
end
end
def self.upcoming_enrollments
all_active = Enrollment.currently_enrolled
date = upcoming_thursday
all_active
.select { |enrollment| eligibility_check_for?(upcoming_thursday) }
.select { |enrollment| past_initial_start_buffer?(enrollment, upcoming_thursday) }
.select { |enrollment| past_enrollment_change_buffer?(enrollment, upcoming_thursday) }
.select { |enrollment| should_give_feedback?(enrollment, upcoming_thursday) }
.select { |enrollment| repeat_feedback_ineligible_before(upcoming_thursday) }
end
private
def eligibility_check_for?(date)
past_enrollment_change_buffer?(self, date) &&
should_give_feedback?(self, date) &&
past_initial_start_buffer?(self, date)
end
def past_initial_start_buffer?(enrollment, dispatch_date)
dispatch_date >= enrollment.course_start_date + 4.weeks
end
def past_enrollment_change_buffer?(enrollment, dispatch_date)
dispatch_date >= enrollment.created_at + 7.days
end
def should_give_feedback?(enrollment, date)
student_feedbacks = Feedback.where(
enrollment_chain_id:
enrollment.chain_id)
student_feedbacks.where(
'created_at > ?', repeat_feedback_ineligible_before(date)).empty?
end
def repeat_feedback_ineligible_before(date)
date - Feedback::REPEAT_DISTANCE.days
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment