Module: TimeAgoInWords

Included in:
Pry::SendTweet::TweetRenderer
Defined in:
lib/time-ago-in-words/lib/time-ago-in-words.rb

Defined Under Namespace

Modules: Units

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.time_ago_in_words(time) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# 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