Class: JsonNodeFormatter

Inherits:
Object
  • Object
show all
Includes:
Indentation
Defined in:
lib/json_node_formatter.rb

Instance Method Summary collapse

Methods included from Indentation

#indent, #unindent

Instance Method Details

#format(nodes) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/json_node_formatter.rb', line 6

def format(nodes)
  if nodes.is_a?(Node)
    return "{\n#{format_single_node(nodes, 1)}\n}"
  end

  json = nodes.map { |node|
    format_single_node(node, 1)
  }.join(",\n")

  "{\n#{json}\n}"
end