Module: Holistics::Utils
- Defined in:
- lib/holistics/utils.rb
Constant Summary collapse
- COLORIZE_MAPPING =
{ green: %w{active success ok}, red: %w{fail failure error cancelled}, yellow: %w{new running pending unknown cancelling} }
Class Method Summary collapse
Class Method Details
.colorize(text) ⇒ Object
9 10 11 12 |
# File 'lib/holistics/utils.rb', line 9 def colorize(text) color = COLORIZE_MAPPING.find { |color, values| values.include?(text) } color ? text.method(color[0]).call : text end |
.duration(secs) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/holistics/utils.rb', line 13 def duration secs [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name| if secs > 0 secs, n = secs.divmod(count) "#{n.to_i} #{name}" end }.compact.reverse.join(' ') end |