Sha256: b2b42aedc0bbb6257d127ca81f75057b6b8b6a7f1849df5b406a2b6432bfbd3b

Contents?: true

Size: 630 Bytes

Versions: 1

Compression:

Stored size: 630 Bytes

Contents

require 'json'
module DocParser
  # The JSONOutput class generates a JSON file containing all rows as seperate
  # Array elements
  # @see Output
  class JSONOutput < Output
    # @!visibility private
    def open_file
      @file << '['
      @doc = {}
    end

    def write_row(row)
      raise 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

    def footer
      @file << ']'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
docparser-0.1.6 lib/docparser/output/json_output.rb