Class: AgeCalculator
- Inherits:
-
Object
- Object
- AgeCalculator
- Defined in:
- lib/age_calculator.rb,
lib/age_calculator/railtie.rb,
lib/age_calculator/version.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
'2.0.0'
Instance Method Summary collapse
- #age(asof: nil) ⇒ Object
-
#initialize(birthday) ⇒ AgeCalculator
constructor
A new instance of AgeCalculator.
- #today ⇒ Object
Constructor Details
#initialize(birthday) ⇒ AgeCalculator
Returns a new instance of AgeCalculator.
6 7 8 9 10 11 12 |
# File 'lib/age_calculator.rb', line 6 def initialize(birthday) @birthday = birthday unless @birthday.is_a?(Date) fail ArgumentError, "#{@birthday.inspect} is not a date" end end |
Instance Method Details
#age(asof: nil) ⇒ Object
14 15 16 |
# File 'lib/age_calculator.rb', line 14 def age(asof: nil) ((asof || today).strftime('%Y%m%d').to_i - @birthday.strftime('%Y%m%d').to_i) / 10000 end |
#today ⇒ Object
18 19 20 |
# File 'lib/age_calculator.rb', line 18 def today Time.respond_to?(:zone) ? Time.zone.today : Date.today end |