Class: Adroit::Age
- Inherits:
-
Object
- Object
- Adroit::Age
- Defined in:
- lib/adroit-age/api.rb
Constant Summary collapse
- @@now =
Time.now.utc.to_date
Instance Attribute Summary collapse
-
#age ⇒ Object
Returns the value of attribute age.
-
#dob ⇒ Object
Returns the value of attribute dob.
-
#now ⇒ Object
Returns the value of attribute now.
Instance Method Summary collapse
- #find_month(dob) ⇒ Object
- #find_with_month(dob, year_cust, month_cust) ⇒ Object
- #find_year(dob) ⇒ Object
- #full_month?(day) ⇒ Boolean
- #full_year?(dob) ⇒ Boolean
- #month_label(month) ⇒ Object
- #year_label(year) ⇒ Object
Instance Attribute Details
#age ⇒ Object
Returns the value of attribute age.
5 6 7 |
# File 'lib/adroit-age/api.rb', line 5 def age @age end |
#dob ⇒ Object
Returns the value of attribute dob.
5 6 7 |
# File 'lib/adroit-age/api.rb', line 5 def dob @dob end |
#now ⇒ Object
Returns the value of attribute now.
5 6 7 |
# File 'lib/adroit-age/api.rb', line 5 def now @now end |
Instance Method Details
#find_month(dob) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/adroit-age/api.rb', line 19 def find_month dob if @@now.month == dob.month 0 elsif @@now.month < dob.month ((12 - dob.month) + @@now.month) - ((full_month? dob.day) ? 0 : 1) elsif @@now.month > dob.month (@@now.month - dob.month) - ((full_month? dob.day) ? 0 : 1) end end |
#find_with_month(dob, year_cust, month_cust) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/adroit-age/api.rb', line 11 def find_with_month dob, year_cust, month_cust year = find_year dob month = find_month dob month_cust_label = month_cust.nil? ? "#{month_label month}" : month_cust year_cust_label = year_cust.nil? ? "#{year_label year}" : year_cust "#{year} #{year_cust_label} and #{month} #{month_cust_label}" end |
#find_year(dob) ⇒ Object
7 8 9 |
# File 'lib/adroit-age/api.rb', line 7 def find_year dob age = @@now.year - dob.year - ((full_year? dob) ? 0 : 1) end |
#full_month?(day) ⇒ Boolean
37 38 39 |
# File 'lib/adroit-age/api.rb', line 37 def full_month? day (@@now.day > day || @@now.day == day) end |
#full_year?(dob) ⇒ Boolean
41 42 43 |
# File 'lib/adroit-age/api.rb', line 41 def full_year? dob (@@now.month > dob.month || (@@now.month == dob.month && @@now.day >= dob.day)) end |
#month_label(month) ⇒ Object
33 34 35 |
# File 'lib/adroit-age/api.rb', line 33 def month_label month month == 1 ? "month" : "months" end |
#year_label(year) ⇒ Object
29 30 31 |
# File 'lib/adroit-age/api.rb', line 29 def year_label year year == 1 ? "year" : "years" end |