module HumanSpeakable
Public Class Methods
format_date(date, year=false)
click to toggle source
# File lib/human_speakable.rb, line 21 def self.format_date(date, year=false) s = case (date - Date.today).to_i when (0) then 'today' when (1) then 'tomorrow' when (2..6) then 'this ' + Date::DAYNAMES[date.wday] when (7..10) then 'next ' + Date::DAYNAMES[date.wday] when (11..14) ['next', Date::DAYNAMES[date.wday], 'the', (date.day.ordinal), 'of', Date::MONTHNAMES[date.month]].join(' ') when (15..21) [Date::DAYNAMES[date.wday], 'the', (date.day.ordinal), 'of', Date::MONTHNAMES[date.month]].join(' ') else ['on the', (date.day.ordinal), 'of', Date::MONTHNAMES[date.month]].join(' ') end year ? s + ' ' + date.year.to_s : s end
format_time(time)
click to toggle source
# File lib/human_speakable.rb, line 42 def self.format_time(time) h, m, meridiem = time.strftime("%-I %M %P").split a = [h] a << ':' + m unless m == '00' a << ' ' + meridiem a.join() end
Public Instance Methods
humanize()
click to toggle source
assumes a string representation of a date
# File lib/human_speakable.rb, line 56 def humanize() date = Date.parse(self) HumanSpeakable.format_date(date) end