Class: Pueri::Age
- Inherits:
-
Object
- Object
- Pueri::Age
- Defined in:
- lib/pueri/age.rb
Overview
Parses a given date string into and Array of age. The array contains the years, months and days of life of the one who was/would be born on the given day.
Instance Attribute Summary collapse
-
#age ⇒ Object
readonly
Returns the value of attribute age.
-
#days_month ⇒ Object
readonly
Returns the value of attribute days_month.
Instance Method Summary collapse
-
#initialize(date) ⇒ Age
constructor
Creates an Age instance.
-
#to_f ⇒ Float
Retrieves the age in days.
-
#to_s(short = false) ⇒ String
Retrieves the age on a readable format.
Constructor Details
#initialize(date) ⇒ Age
Creates an Age instance.
13 14 15 16 |
# File 'lib/pueri/age.rb', line 13 def initialize(date) @days_month = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] @age = parse_age(date) end |
Instance Attribute Details
#age ⇒ Object (readonly)
Returns the value of attribute age.
8 9 10 |
# File 'lib/pueri/age.rb', line 8 def age @age end |
#days_month ⇒ Object (readonly)
Returns the value of attribute days_month.
8 9 10 |
# File 'lib/pueri/age.rb', line 8 def days_month @days_month end |
Instance Method Details
#to_f ⇒ Float
Retrieves the age in days.
34 35 36 37 38 39 |
# File 'lib/pueri/age.rb', line 34 def to_f a = age[0].to_f * 365.25 a += age[1].to_f * 30.0 a += age[2].to_f a.round(2) end |
#to_s(short = false) ⇒ String
Retrieves the age on a readable format.
23 24 25 26 27 28 29 |
# File 'lib/pueri/age.rb', line 23 def to_s(short = false) if short short_string else long_string end end |