Method: Twig::CommitTime#initialize
- Defined in:
- lib/twig/commit_time.rb
#initialize(time) ⇒ CommitTime
Returns a new instance of CommitTime.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/twig/commit_time.rb', line 9 def initialize(time) @time = time suffix = 'ago' # Cache calculations against current time years_ago = count_years_ago months_ago = count_months_ago weeks_ago = count_weeks_ago days_ago = count_days_ago hours_ago = count_hours_ago minutes_ago = count_minutes_ago seconds_ago = count_seconds_ago @time_ago = if years_ago > 0 "#{years_ago}y" elsif months_ago > 0 and weeks_ago > 4 "#{months_ago}mo" elsif weeks_ago > 0 "#{weeks_ago}w" elsif days_ago > 0 "#{days_ago}d" elsif hours_ago > 0 "#{hours_ago}h" elsif minutes_ago > 0 "#{minutes_ago}m" else "#{seconds_ago}s" end @time_ago << ' ' << suffix end |