Module: Integrity::Helpers::PrettyOutput
- Included in:
- Integrity::Helpers
- Defined in:
- lib/integrity/helpers/pretty_output.rb
Instance Method Summary collapse
- #bash_color_codes(string) ⇒ Object
- #cycle(*values) ⇒ Object
- #pretty_date(date_time) ⇒ Object
- #strftime_with_ordinal(date_time, format_string) ⇒ Object
Instance Method Details
#bash_color_codes(string) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/integrity/helpers/pretty_output.rb', line 11 def bash_color_codes(string) string.gsub("\e[0m", '</span>'). gsub("\e[31m", '<span class="color31">'). gsub("\e[32m", '<span class="color32">'). gsub("\e[33m", '<span class="color33">'). gsub("\e[34m", '<span class="color34">'). gsub("\e[35m", '<span class="color35">'). gsub("\e[36m", '<span class="color36">'). gsub("\e[37m", '<span class="color37">') end |
#cycle(*values) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/integrity/helpers/pretty_output.rb', line 4 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 |
#pretty_date(date_time) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/integrity/helpers/pretty_output.rb', line 22 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 |
#strftime_with_ordinal(date_time, format_string) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/integrity/helpers/pretty_output.rb', line 33 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 |