Class: Hotdog::Formatters::Json

Inherits:
BaseFormatter show all
Defined in:
lib/hotdog/formatters/json.rb

Instance Method Summary collapse

Instance Method Details

#format(result, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/hotdog/formatters/json.rb', line 8

def format(result, options={})
  result = prepare(result)
  if options[:headers] and options[:fields]
    result.map! do |record|
      Hash[options[:fields].zip(record)]
    end
    JSON.pretty_generate(result) + newline
  else
    JSON.pretty_generate(result) + newline
  end
end