Sha256: fad076dd39264ed126b2ac6d39020cb2e397659c5fc1927b859c15254ce115c6

Contents?: true

Size: 608 Bytes

Versions: 2

Compression:

Stored size: 608 Bytes

Contents

module LineLog
  module Formatters
    class KeyValue
      def call(data)
        data.keys
          .map { |key| format(key, data[key]) }
          .join(' ')
      end

      protected

      def format(key, value)
        "#{key}=#{parse_value(key, value)}"
      end

      def parse_value(key, value)
        # Exactly preserve the previous output
        # Parsing this can be ambigious if the error messages contains
        # a single quote
        return "'#{value}'" if value.is_a? String
        return Kernel.format('%.2f', value) if value.is_a? Float

        value
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
line_log-0.1.1 lib/line_log/formatters/key_value.rb
line_log-0.1.0 lib/line_log/formatters/key_value.rb