class Time
Public Instance Methods
pretty(clock=Time.now)
click to toggle source
Clock argument for testing; defaults to Time
# File lib/pretty/pretty.rb, line 4 def pretty(clock=Time.now) @expired = (clock-self).to_i @today = clock.strftime('%A') @created = self.to_time.strftime('%A') @days = { "Monday" => 1, "Tuesday" => 2, "Wednesday" => 3, "Thursday" => 4, "Friday" => 5, "Saturday" => 6, "Sunday" => 7 } return just_now if just_now? return a_second_ago if a_second_ago? return seconds_ago if seconds_ago? return a_minute_ago if a_minute_ago? return minutes_ago if minutes_ago? return an_hour_ago if an_hour_ago? return today if is_today? return yesterday if is_yesterday? return this_week if this_week? return last_week if last_week? return datetimefiesta end
Private Instance Methods
a_minute_ago()
click to toggle source
# File lib/pretty/pretty.rb, line 57 def a_minute_ago 'a minute ago' end
a_minute_ago?()
click to toggle source
# File lib/pretty/pretty.rb, line 61 def a_minute_ago? @expired >= 60 && @expired <= 119 #120 = 2 minutes end
a_second_ago()
click to toggle source
# File lib/pretty/pretty.rb, line 41 def a_second_ago 'a second ago' end
a_second_ago?()
click to toggle source
# File lib/pretty/pretty.rb, line 45 def a_second_ago? @expired == 1 end
an_hour_ago()
click to toggle source
# File lib/pretty/pretty.rb, line 73 def an_hour_ago 'an hour ago' end
an_hour_ago?()
click to toggle source
# File lib/pretty/pretty.rb, line 77 def an_hour_ago? @expired >= 3600 && @expired <= 7199 # 3600 = 1 hour end
datetimefiesta()
click to toggle source
# File lib/pretty/pretty.rb, line 117 def datetimefiesta self.strftime("%A, %B %e at%l:%M%p") end
is_today?()
click to toggle source
# File lib/pretty/pretty.rb, line 89 def is_today? @days[@today] - @days[@created] == 0 && @expired >= 7200 && @expired <= 82800 end
is_yesterday?()
click to toggle source
# File lib/pretty/pretty.rb, line 97 def is_yesterday? (@days[@today] - @days[@created] == 1 || @days[@created] + @days[@today] == 8) && @expired <= 172800 end
just_now()
click to toggle source
# File lib/pretty/pretty.rb, line 33 def just_now 'just now' end
just_now?()
click to toggle source
# File lib/pretty/pretty.rb, line 37 def just_now? @expired == 0 end
last_week()
click to toggle source
# File lib/pretty/pretty.rb, line 109 def last_week "Last #{@created} at#{timeify}" end
last_week?()
click to toggle source
# File lib/pretty/pretty.rb, line 113 def last_week? @expired >= 518400 && @expired <= 1123200 end
minutes_ago()
click to toggle source
# File lib/pretty/pretty.rb, line 65 def minutes_ago (@expired/60).to_i.to_s+' minutes ago' end
minutes_ago?()
click to toggle source
# File lib/pretty/pretty.rb, line 69 def minutes_ago? @expired >= 120 && @expired <= 3599 end
seconds_ago()
click to toggle source
# File lib/pretty/pretty.rb, line 49 def seconds_ago @expired.to_s+' seconds ago' end
seconds_ago?()
click to toggle source
# File lib/pretty/pretty.rb, line 53 def seconds_ago? @expired >= 2 && @expired <= 59 end
this_week()
click to toggle source
# File lib/pretty/pretty.rb, line 101 def this_week "#{@created} at#{timeify}" end
this_week?()
click to toggle source
# File lib/pretty/pretty.rb, line 105 def this_week? @expired <= 604800 && @days[@today] - @days[@created] != 0 end
timeify()
click to toggle source
# File lib/pretty/pretty.rb, line 85 def timeify "#{self.to_time.strftime("%l:%M%p")}" end
today()
click to toggle source
# File lib/pretty/pretty.rb, line 81 def today "Today at#{timeify}" end
yesterday()
click to toggle source
# File lib/pretty/pretty.rb, line 93 def yesterday "Yesterday at#{timeify}" end