Sha256: a8a6900c470062db966ea82412c179e9c1da2333af50d46c23e8dbeab6d76b00

Contents?: true

Size: 589 Bytes

Versions: 1

Compression:

Stored size: 589 Bytes

Contents

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

    def write_row(row)
      if @first
        @first = false
      else
        @file << ','
      end
      0.upto(@header.length - 1) do |counter|
        @doc[@header[counter]] = row[counter] rescue ''
      end
      @file << JSON.dump(@doc)
    end

    def close
      @file << ']'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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