Class: AwesomePrint::Formatter
- Includes:
- Colorize
- Defined in:
- lib/awesome_print/formatter.rb
Constant Summary collapse
- CORE_FORMATTERS =
[:array, :bigdecimal, :class, :dir, :file, :hash, :method, :rational, :set, :struct, :unboundmethod]
Instance Attribute Summary collapse
-
#inspector ⇒ Object
readonly
Returns the value of attribute inspector.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#cast(object, type) ⇒ Object
Hook this when adding custom formatters.
-
#format(object, type = nil) ⇒ Object
Main entry point to format an object.
-
#initialize(inspector) ⇒ Formatter
constructor
A new instance of Formatter.
Methods included from Colorize
Constructor Details
#initialize(inspector) ⇒ Formatter
Returns a new instance of Formatter.
16 17 18 19 |
# File 'lib/awesome_print/formatter.rb', line 16 def initialize(inspector) @inspector = inspector @options = inspector. end |
Instance Attribute Details
#inspector ⇒ Object (readonly)
Returns the value of attribute inspector.
12 13 14 |
# File 'lib/awesome_print/formatter.rb', line 12 def inspector @inspector end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/awesome_print/formatter.rb', line 12 def @options end |
Instance Method Details
#cast(object, type) ⇒ Object
Hook this when adding custom formatters. Check out lib/awesome_print/ext directory for custom formatters that ship with awesome_print.
36 37 38 |
# File 'lib/awesome_print/formatter.rb', line 36 def cast(object, type) CORE_FORMATTERS.include?(type) ? type : :self end |
#format(object, type = nil) ⇒ Object
Main entry point to format an object.
23 24 25 26 27 28 29 30 31 |
# 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 awesome end |