Class: Dicey::OutputFormatters::HashFormatter Abstract

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

Overview

This class is abstract.

Base formatter for outputting in formats which can be converted from a Hash directly. Can add an optional description into the result.

Direct Known Subclasses

JSONFormatter, YAMLFormatter

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 to result as an extra key

Returns:

  • (String)


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

def call(hash, description = nil)
  hash = hash.transform_keys { to_primitive(_1) }
  hash.transform_values! { to_primitive(_1) }
  output = {}
  output["description"] = description if description
  output["results"] = hash
  output.public_send(self.class::METHOD)
end