Class: Lumberjack::Formatter::StructuredFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::StructuredFormatter
- Defined in:
- lib/lumberjack/formatter/structured_formatter.rb
Overview
Dereference arrays and hashes and recursively call formatters on each element.
Instance Method Summary collapse
- #call(obj) ⇒ Object
-
#initialize(formatter = nil) ⇒ StructuredFormatter
constructor
A new instance of StructuredFormatter.
Constructor Details
#initialize(formatter = nil) ⇒ StructuredFormatter
Returns a new instance of StructuredFormatter.
9 10 11 |
# File 'lib/lumberjack/formatter/structured_formatter.rb', line 9 def initialize(formatter = nil) @formatter = formatter end |
Instance Method Details
#call(obj) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lumberjack/formatter/structured_formatter.rb', line 13 def call(obj) if obj.is_a?(Hash) hash = {} references ||= Set.new obj.each do |name, value| hash[name.to_s] = call(value) end hash elsif obj.is_a?(Enumerable) && obj.respond_to?(:size) && obj.size != Float::INFINITY obj.collect { |element| call(element) } elsif @formatter @formatter.format(obj) else obj end end |