Class: Float

Inherits:
Object
  • Object
show all
Defined in:
lib/usaidwat/ext/time.rb

Instance Method Summary collapse

Instance Method Details

#agoObject

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/usaidwat/ext/time.rb', line 54

def ago
  raise ArgumentError, "Delta is negative: #{self}" if negative?
  case minutes_ago.to_i
  when 0..1
    case seconds_ago.to_i
    when 0..5   then "less than 5 seconds ago"
    when 6..10  then "less than 10 seconds ago"
    when 11..20 then "less than 20 seconds ago"
    when 21..40 then "half a minute ago"
    when 41..59 then "less than a minute ago"
    else             "a minute ago"
    end
  when 2..45           then "#{minutes_ago.round} minutes ago"
  when 46..90          then "about an hour ago"
  when 90..1440        then "about #{hours_ago.round} hours ago"
  when 1441..2880      then "a day ago"
  when 2881..10080     then "about #{days_ago.round} days ago"
  when 10081..43220    then "about #{weeks_ago.round} #{"week".pluralize(weeks_ago.round)} ago"
  when 43221..525960   then "about #{months_ago.round} #{"month".pluralize(months_ago.round)} ago"
  when 525960..1051920 then "about a year ago"
  else                      "over #{years_ago.to_i} years ago"
  end
end

#days_agoObject



90
91
92
# File 'lib/usaidwat/ext/time.rb', line 90

def days_ago
  hours_ago / 24.0
end

#hours_agoObject



86
87
88
# File 'lib/usaidwat/ext/time.rb', line 86

def hours_ago
  minutes_ago / 60.0
end

#minutes_agoObject



82
83
84
# File 'lib/usaidwat/ext/time.rb', line 82

def minutes_ago
  seconds_ago / 60.0
end

#months_agoObject



98
99
100
# File 'lib/usaidwat/ext/time.rb', line 98

def months_ago
  days_ago / 30.0
end

#seconds_agoObject



78
79
80
# File 'lib/usaidwat/ext/time.rb', line 78

def seconds_ago
  self
end

#weeks_agoObject



94
95
96
# File 'lib/usaidwat/ext/time.rb', line 94

def weeks_ago
  days_ago / 7.0
end

#years_agoObject



102
103
104
# File 'lib/usaidwat/ext/time.rb', line 102

def years_ago
  days_ago / 365.0
end