Module: DZEN::Helpers
- Defined in:
- lib/dzen/helpers.rb
Overview
Some small helpers used in app module outputs.
You have to
include DZEN::Helpers
in your app file to actually use them.
Instance Method Summary collapse
-
#_color(c, text) ⇒ Object
Public: Colorize a given string using the callbacks defined by DZEN::Base (or its subclass).
-
#color_critical(n, critical, options = {}) ⇒ Object
Public: Colorize a number based on wether it’s below a critical value or not.
Instance Method Details
#_color(c, text) ⇒ Object
Public: Colorize a given string using the callbacks
defined by DZEN::Base (or its subclass).
c - The color string, like “red” or “#ff0000”
Make sure the implementation of config.color callbacks
can interpret this colors.
text - The text to be colored.
Returns the colored string.
20 21 22 23 |
# File 'lib/dzen/helpers.rb', line 20 def _color(c, text) config = dzen.config.color %|#{config[:start].call(c)}#{text}#{config[:end].call(c)}| end |
#color_critical(n, critical, options = {}) ⇒ Object
Public: Colorize a number based on wether it’s
below a critical value or not.
n - The number to colorize. critical - The critical value. options - A Hash of colors for the different colors
:normal - for the value equal or below `critical`
:critical - for the value above `critical`
Returns the colored string.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dzen/helpers.rb', line 35 def color_critical(n, critical, = {}) = { :normal => "#ff8700", :critical => "red" }.merge() if n.to_i == 0 n.to_s elsif n.to_i < critical _color([:normal], n.to_i) else _color([:critical], n.to_i) end end |