module TimeAgoInWords
Constants
- VERSION
Public Instance Methods
time_ago_in_words(time)
click to toggle source
# File lib/time-ago-in-words/lib/time-ago-in-words.rb, line 20 def time_ago_in_words(time) time_difference = Time.now.to_i - time.to_i if time_difference <= 0 return "0 seconds since Last Refresh" end unit = get_unit(time_difference) unit_rep = time_difference > 1 ? "#{unit.to_s.downcase}s" : unit.to_s.downcase unit_difference = time_difference / Units.const_get(unit.capitalize) "#{unit_difference} #{unit_rep}" end
Private Instance Methods
get_unit(time_difference)
click to toggle source
# File lib/time-ago-in-words/lib/time-ago-in-words.rb, line 32 def get_unit(time_difference) Units.constants.each_cons(2) do |con| return con.first if (Units.const_get(con[0])...Units.const_get(con[1])) === time_difference end end