Class: AgeJp::Calculator
- Inherits:
-
Object
- Object
- AgeJp::Calculator
- Defined in:
- lib/age_jp/calculator.rb
Instance Method Summary collapse
- #age ⇒ Object
- #age_at(date) ⇒ Object
- #age_jp ⇒ Object
- #age_jp_at(date) ⇒ Object
- #east_asian_age_reckoning ⇒ Object
- #east_asian_age_reckoning_at(date) ⇒ Object
-
#initialize(birthday) ⇒ Calculator
constructor
A new instance of Calculator.
- #today ⇒ Object
Constructor Details
#initialize(birthday) ⇒ Calculator
Returns a new instance of Calculator.
3 4 5 |
# File 'lib/age_jp/calculator.rb', line 3 def initialize(birthday) @birthday = birthday end |
Instance Method Details
#age ⇒ Object
7 8 9 10 11 |
# File 'lib/age_jp/calculator.rb', line 7 def age return unless valid_birthday? calculate_age(today) end |
#age_at(date) ⇒ Object
13 14 15 16 17 |
# File 'lib/age_jp/calculator.rb', line 13 def age_at(date) return unless valid_birthday? && valid_date?(date) calculate_age(date) end |
#age_jp ⇒ Object
19 20 21 22 23 |
# File 'lib/age_jp/calculator.rb', line 19 def age_jp return unless valid_birthday? calculate_age_jp(today) end |
#age_jp_at(date) ⇒ Object
25 26 27 28 29 |
# File 'lib/age_jp/calculator.rb', line 25 def age_jp_at(date) return unless valid_birthday? && valid_date?(date) calculate_age_jp(date) end |
#east_asian_age_reckoning ⇒ Object
31 32 33 34 35 36 |
# File 'lib/age_jp/calculator.rb', line 31 def east_asian_age_reckoning return unless valid_birthday? age = calculate_age(today) until_birthday_this_year?(today) ? age + 2 : age + 1 end |
#east_asian_age_reckoning_at(date) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/age_jp/calculator.rb', line 38 def east_asian_age_reckoning_at(date) return unless valid_birthday? && valid_date?(date) age = calculate_age(date) until_birthday_this_year?(date) ? age + 2 : age + 1 end |
#today ⇒ Object
45 46 47 |
# File 'lib/age_jp/calculator.rb', line 45 def today Date.today end |