jam-cloud/ruby/lib/jam_ruby/models/teacher.rb

47 lines
1.3 KiB
Ruby

module JamRuby
class Teacher < ::ActiveRecord::Base
belongs_to :user
belongs_to :school, class_name: "JamRuby::School"
belongs_to :retailer, class_name: "JamRuby::Retailer"
# Rails 4 code relied on this helper to pick any "ready" teacher for
# auto-assigned lesson prompts. Keep a minimal compatibility version.
def self.match_teacher(_user = nil)
joins(:user).where.not(ready_for_session_at: nil).first
end
def booking_price(lesson_length, per_lesson = true)
key = if per_lesson
"price_per_lesson_#{lesson_length}_cents"
else
"price_per_month_#{lesson_length}_cents"
end
return nil unless respond_to?(key)
cents = send(key)
return nil if cents.nil?
cents.to_f / 100.0
end
def booking_price_table
[30, 45, 60, 90, 120].each_with_object({}) do |duration, memo|
memo[duration] = {
per_lesson: booking_price(duration, true),
per_month: booking_price(duration, false)
}
end
end
# Legacy user callbacks expect this method to exist.
# Keep behavior minimal and non-invasive for test compatibility.
def update_profile_pct
return profile_pct unless profile_pct.nil?
self.profile_pct = 0
save(validate: false)
profile_pct
end
end
end