Sha256: 6135299d6da29f193f6c59e672efdd87b5569fe2e3e05a04fb0beba304201acc

Contents?: true

Size: 656 Bytes

Versions: 1

Compression:

Stored size: 656 Bytes

Contents

# frozen_string_literal: true

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.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

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

Version data entries

1 entries across 1 versions & 1 rubygems

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