module Reality::Helpers

@private Just assorted “cool things”, included into all entities Subject to change/refactor

Public Instance Methods

age() click to toggle source
# File lib/reality/definitions/helpers.rb, line 29
def age
  age_at(Date.today)
end
age_at(tm) click to toggle source
# File lib/reality/definitions/helpers.rb, line 16
def age_at(tm)
  # TimeBoots fail with Time vs Date :(
  #birthday && TimeBoots.year.measure(birthday, tm)

  from = birthday || created_at || published_at

  if from.month < tm.month || from.month == tm.month && from.day <= tm.day
    tm.year - from.year
  else
    tm.year - from.year - 1
  end
end
alive?() click to toggle source
# File lib/reality/definitions/helpers.rb, line 8
def alive?
  !birthday.nil? && date_of_death.nil?
end
dead?() click to toggle source
# File lib/reality/definitions/helpers.rb, line 12
def dead?
  !date_of_death.nil?
end