Parent

AwesomePrint::Formatter

Public Class Methods

new(inspector) click to toggle source
# File lib/awesome_print/formatter.rb, line 15
def initialize(inspector)
  @inspector   = inspector
  @options     = inspector.options
  @indentation = @options[:indent].abs
end

Public Instance Methods

cast(object, type) click to toggle source

Hook this when adding custom formatters. Check out lib/awesome_print/ext directory for custom formatters that ship with awesome_print.

# File lib/awesome_print/formatter.rb, line 36
def cast(object, type)
  CORE.grep(type)[0] || :self
end
colorize(s, type) click to toggle source

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

# File lib/awesome_print/formatter.rb, line 42
def colorize(s, type)
  s = CGI.escapeHTML(s) if @options[:html]
  if @options[:plain] || !@options[:color][type] || !@inspector.colorize?
    s
  else
    s.send(@options[:color][type], @options[:html])
  end
end
format(object, type = nil) click to toggle source

Main entry point to format an object.

# File lib/awesome_print/formatter.rb, line 23
def format(object, type = nil)
  core_class = cast(object, type)
  awesome = if core_class != :self
    send(:"awesome_#{core_class}", object) # Core formatters.
  else
    awesome_self(object, type) # Catch all that falls back to object.inspect.
  end
  @options[:html] ? "<pre>#{awesome}</pre>" : awesome
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.