Class: Synthra::Output::JsonFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/synthra/output/json_formatter.rb

Overview

JSON formatter for generated data

Instance Method Summary collapse

Instance Method Details

#format(record, pretty: false) ⇒ String

Format a single record

Parameters:

  • record (Hash)

    the record

  • pretty (Boolean) (defaults to: false)

    pretty-print

Returns:

  • (String)

    JSON string



15
16
17
18
19
20
21
# File 'lib/synthra/output/json_formatter.rb', line 15

def format(record, pretty: false)
  if pretty
    JSON.pretty_generate(record)
  else
    JSON.generate(record)
  end
end

#format_many(records, pretty: false) ⇒ String

Format multiple records

Parameters:

  • records (Array<Hash>)

    the records

  • pretty (Boolean) (defaults to: false)

    pretty-print

Returns:

  • (String)

    JSON string



30
31
32
33
34
35
36
# File 'lib/synthra/output/json_formatter.rb', line 30

def format_many(records, pretty: false)
  if pretty
    JSON.pretty_generate(records)
  else
    JSON.generate(records)
  end
end