Class: DocParser::JSONOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/docparser/output/json_output.rb

Overview

The JSONOutput class generates a JSON file containing all rows as seperate Array elements

See Also:

Instance Attribute Summary

Attributes inherited from Output

#filename, #rowcount

Instance Method Summary collapse

Methods inherited from Output

#add_row, #close, #header, #header=, #initialize

Constructor Details

This class inherits a constructor from DocParser::Output

Instance Method Details


25
26
27
# File 'lib/docparser/output/json_output.rb', line 25

def footer
  @file << ']'
end

#write_row(row) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/docparser/output/json_output.rb', line 13

def write_row(row)
  fail MissingHeaderException if @header.nil? || @header.length == 0

  @file << ',' unless @file.pos <= 1

  0.upto(@header.length - 1) do |counter|
    @doc[@header[counter]] = row.length > counter ? row[counter] : ''
  end

  @file << JSON.generate(@doc)
end