Class: Kidsmin::Child
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Kidsmin::Child
- Defined in:
- app/models/kidsmin/child.rb
Constant Summary collapse
- GRADE_DISPLAY =
{ 0 => "K", 1 => "1st", 2 => "2nd", 3 => "3rd", 4 => "4th", 5 => "5th", 6 => "6th", 7 => "7th", 8 => "8th", 9 => "9th", 10 => "10th", 11 => "11th", 12 => "12th" }.freeze
- GRADE_PARSE =
{ "k" => 0, "kindergarten" => 0, "1" => 1, "1st" => 1, "2" => 2, "2nd" => 2, "3" => 3, "3rd" => 3, "4" => 4, "4th" => 4, "5" => 5, "5th" => 5, "6" => 6, "6th" => 6, "7" => 7, "7th" => 7, "8" => 8, "8th" => 8, "9" => 9, "9th" => 9, "10" => 10, "10th" => 10, "11" => 11, "11th" => 11, "12" => 12, "12th" => 12 }.freeze
Instance Method Summary collapse
- #age ⇒ Object
- #full_name ⇒ Object
-
#grade=(val) ⇒ Object
Accept PCO integer or human string (“3rd”, “K”) — store as integer.
-
#grade_display ⇒ Object
Human-readable display (“3rd”, “K”) for the UI.
Instance Method Details
#age ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/models/kidsmin/child.rb', line 41 def age return nil if birthdate.nil? today = Date.current years = today.year - birthdate.year years -= 1 if today < birthdate + years.years years end |
#full_name ⇒ Object
37 38 39 |
# File 'app/models/kidsmin/child.rb', line 37 def full_name "#{first_name} #{last_name}" end |
#grade=(val) ⇒ Object
Accept PCO integer or human string (“3rd”, “K”) — store as integer
24 25 26 27 28 29 30 |
# File 'app/models/kidsmin/child.rb', line 24 def grade=(val) if val.is_a?(Integer) || val.nil? super(val) else super(GRADE_PARSE[val.to_s.strip.downcase]) end end |
#grade_display ⇒ Object
Human-readable display (“3rd”, “K”) for the UI
33 34 35 |
# File 'app/models/kidsmin/child.rb', line 33 def grade_display GRADE_DISPLAY[grade] end |