Class: Happybirthday::Age
Instance Attribute Summary collapse
-
#birthday ⇒ Object
readonly
Returns the value of attribute birthday.
-
#present_day ⇒ Object
readonly
Returns the value of attribute present_day.
Instance Method Summary collapse
-
#at(date) ⇒ Happybirthday::Age
Get Happybirthday::Age object which has specific date you passed.
-
#initialize(birthday:, present_day: Date.today) ⇒ Happybirthday::Age
constructor
Happybirthday::Age initializer.
-
#years_after(year = 0) ⇒ Happybirthday::Age
Get Happybirthday::Age object which has future date.
-
#years_before(year = 0) ⇒ Happybirthday::Age
Get Happybirthday::Age object which has past date.
-
#years_old ⇒ Integer?
Get age.
Constructor Details
#initialize(birthday:, present_day: Date.today) ⇒ Happybirthday::Age
Happybirthday::Age initializer
9 10 11 12 |
# File 'lib/happybirthday/age.rb', line 9 def initialize(birthday:, present_day: Date.today) @birthday = birthday @present_day = present_day end |
Instance Attribute Details
#birthday ⇒ Object (readonly)
Returns the value of attribute birthday.
3 4 5 |
# File 'lib/happybirthday/age.rb', line 3 def birthday @birthday end |
#present_day ⇒ Object (readonly)
Returns the value of attribute present_day.
3 4 5 |
# File 'lib/happybirthday/age.rb', line 3 def present_day @present_day end |
Instance Method Details
#at(date) ⇒ Happybirthday::Age
Get Happybirthday::Age object which has specific date you passed
26 27 28 |
# File 'lib/happybirthday/age.rb', line 26 def at(date) Age.new(birthday: birthday, present_day: to_date(date)) end |
#years_after(year = 0) ⇒ Happybirthday::Age
Get Happybirthday::Age object which has future date
40 41 42 |
# File 'lib/happybirthday/age.rb', line 40 def years_after(year = 0) Age.new(birthday: birthday, present_day: present_day.next_year(year)) end |
#years_before(year = 0) ⇒ Happybirthday::Age
Get Happybirthday::Age object which has past date
33 34 35 |
# File 'lib/happybirthday/age.rb', line 33 def years_before(year = 0) Age.new(birthday: birthday, present_day: present_day.prev_year(year)) end |
#years_old ⇒ Integer?
Get age
17 18 19 20 21 |
# File 'lib/happybirthday/age.rb', line 17 def years_old return nil if present_day < birthday.date format = "%Y%m%d" (present_day.strftime(format).to_i - birthday.date.strftime(format).to_i) / 10000 end |