module Integrity module Helpers module PrettyOutput def cycle(*values) @cycles ||= {} @cycles[values] ||= -1 # first value returned is 0 next_value = @cycles[values] = (@cycles[values] + 1) % values.size values[next_value] end def bash_color_codes(string) string.gsub("\e[0m", ''). gsub("\e[31m", ''). gsub("\e[32m", ''). gsub("\e[33m", ''). gsub("\e[34m", ''). gsub("\e[35m", ''). gsub("\e[36m", ''). gsub("\e[37m", '') end def pretty_date(date_time) days_away = (Date.today - Date.new(date_time.year, date_time.month, date_time.day)).to_i if days_away == 0 "today" elsif days_away == 1 "yesterday" else strftime_with_ordinal(date_time, "on %b %d%o") end end def strftime_with_ordinal(date_time, format_string) ordinal = case date_time.day when 1, 21, 31 then "st" when 2, 22 then "nd" when 3, 23 then "rd" else "th" end date_time.strftime(format_string.gsub("%o", ordinal)) end end end end