Class: Dicey::OutputFormatters::KeyValueFormatter Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/dicey/output_formatters/key_value_formatter.rb

Overview

This class is abstract.

Base formatter for outputting lists of key-value pairs separated by newlines. Can add an optional description into the result.

Direct Known Subclasses

GnuplotFormatter, ListFormatter

Instance Method Summary collapse

Instance Method Details

#call(hash, description = nil) ⇒ String

Parameters:

  • hash (Hash{Object => Object})
  • description (String) (defaults to: nil)

    text to add as a comment.

Returns:

  • (String)


12
13
14
15
16
17
# File 'lib/dicey/output_formatters/key_value_formatter.rb', line 12

def call(hash, description = nil)
  initial_string = description ? "# #{description}\n" : +""
  hash.each_with_object(initial_string) do |(key, value), output|
    output << "#{key}#{self.class::SEPARATOR}#{value}\n"
  end
end