config/initializers/duration.rb
# Returns a pediatric age duration.
#
# Parts to be used when displaying a pediatric age:
#
#     | Age         | Lower Part | Higher Part |
#     | ----------- | ---------- | ----------- |
#     | < 2 hours   | minutes    | minutes     |
#     | < 2 days    | hours      | hours       |
#     | < 4 weeks   | days       | days        |
#     | < 1 year    | weeks      | days        |
#     | < 2 years   | months     | days        |
#     | < 18 years  | years      | months      |
#     | >= 18 years | years      | years       |
Returns a pediatric age duration.
Parts to be used when displaying a pediatric age.


Returns a pediatric age duration . Parts to be used when displaying a pediatric age .
def pediatric
      if self < 4.weeks
        self.in_days.floor.days
      elsif self.parts[:years].nil? 
        age_in_weeks = self.in_weeks.floor.weeks
        age_in_days  = (self - age_in_weeks).in_days.floor.days
        age_in_weeks + age_in_days
      elsif self.parts[:years] == 1 
        age_in_months = self.in_months.floor.months
        age_in_days  = (self - age_in_months).in_days.floor.days
        age_in_months + age_in_days
      elsif self.parts[:years] < 18 
        age_in_years = self.parts[:years].years
        age_in_months = self.parts[:months].to_i.months
        age_in_years + age_in_months
      else 
        self.parts[:years].years
      end
    end
def pediatric if self < 4 . weeks self . in_days . floor . days elsif self . parts [ :years ] . nil? age_in_weeks = self . in_weeks . floor . weeks age_in_days = ( self - age_in_weeks ) . in_days . floor . days age_in_weeks + age_in_days elsif self . parts [ :years ] == 1 age_in_months = self . in_months . floor . months age_in_days = ( self - age_in_months ) . in_days . floor . days age_in_months + age_in_days elsif self . parts [ :years ] < 18 age_in_years = self . parts [ :years ] . years age_in_months = self . parts [ :months ] . to_i . months age_in_years + age_in_months else self . parts [ :years ] . years end end
Returns a pediatric age duration.
Returns a pediatric age duration .
# age < 1.year # age < 2.years # age < 18.years # >= 18 years