Class: Logged::Formatter::KeyValue
- Defined in:
- lib/logged/formatter/key_value.rb
Overview
Key-Value formatter for logged
Instance Method Summary collapse
Instance Method Details
#call(data) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/logged/formatter/key_value.rb', line 9 def call(data) data .reject { |_k, v| v.nil? || (v.is_a?(String) && v.blank?) } .map { |k, v| format_key(k, v) } .join(' ') end |
#format_key(key, value) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/logged/formatter/key_value.rb', line 16 def format_key(key, value) # encapsulate in single quotes if value is a string value = "'#{value}'" if value.is_a?(String) # ensure only two decimals value = Kernel.format('%.2f', value) if value.is_a?(Float) "#{key}=#{value}" end |