class Adroit::Age

Attributes

age[RW]
dob[RW]
now[RW]

Public Instance Methods

find_month(dob) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/adroit-age/api.rb, line 37
def full_month? day
    (@@now.day > day || @@now.day == day)
end
full_year?(dob) click to toggle source
# 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) click to toggle source
# File lib/adroit-age/api.rb, line 33
def month_label month
    month == 1 ? "month" : "months" 
end
year_label(year) click to toggle source
# File lib/adroit-age/api.rb, line 29
def year_label year
    year == 1 ? "year" : "years"
end