Class: Tabula::Writers::JSONWriter
- Defined in:
- lib/tabula/writers/json_writer.rb
Overview
Writes tables in JSON format
Instance Method Summary collapse
-
#initialize(pretty: false, include_metadata: true, **options) ⇒ JSONWriter
constructor
A new instance of JSONWriter.
-
#write(tables, io) ⇒ Object
Write tables to an IO object.
Methods inherited from Writer
Constructor Details
#initialize(pretty: false, include_metadata: true, **options) ⇒ JSONWriter
Returns a new instance of JSONWriter.
11 12 13 14 15 |
# File 'lib/tabula/writers/json_writer.rb', line 11 def initialize(pretty: false, include_metadata: true, **) super(**) @pretty = pretty = end |
Instance Method Details
#write(tables, io) ⇒ Object
Write tables to an IO object
20 21 22 23 24 25 26 27 28 |
# File 'lib/tabula/writers/json_writer.rb', line 20 def write(tables, io) output = tables.map { |table| table_to_hash(table) } if @pretty io.puts JSON.pretty_generate(output) else io.puts JSON.generate(output) end end |