Module: AmazingPrint::Colorize

Included in:
Formatter, Formatters::BaseFormatter
Defined in:
lib/amazing_print/colorize.rb

Instance Method Summary collapse

Instance Method Details

#colorize(str, type) ⇒ Object

Pick the color and apply it to the given string as necessary.




7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/amazing_print/colorize.rb', line 7

def colorize(str, type)
  str = CGI.escapeHTML(str) if options[:html]
  if options[:plain] || !options[:color][type] || !inspector.colorize?
    str
  #
  # Check if the string color method is defined by amazing_print and accepts
  # html parameter or it has been overriden by some gem such as colorize.
  #
  elsif str.method(options[:color][type]).arity == -1 # Accepts html parameter.
    str.send(options[:color][type], options[:html])
  else
    if options[:html]
      str = %(<kbd style="color:#{options[:color][type]}">#{str}</kbd>)
    end
    str.send(options[:color][type])
  end
end