class DocParser::JSONOutput

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

Public Instance Methods

open_file() click to toggle source

@!visibility private

# File lib/docparser/output/json_output.rb, line 10
def open_file
  @file << '['
  @doc = {}
end
write_row(row) click to toggle source
# File lib/docparser/output/json_output.rb, line 15
def write_row(row)
  raise MissingHeaderException if @header.nil? || @header.empty?

  @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