lib/docparser/output/json_output.rb in docparser-0.0.1 vs lib/docparser/output/json_output.rb in docparser-0.1.0
- old
+ new
@@ -1,30 +1,35 @@
require 'json'
module DocParser
# The JSONOutput class generates a JSON file containing all rows as seperate
- # JSON documents
+ # Array elements
# @see Output
class JSONOutput < Output
# @!visibility private
def open_file
@file << '['
@first = true
@doc = {}
end
def write_row(row)
+ raise MissingHeaderException if @header.nil? || @header.length == 0
if @first
@first = false
else
@file << ','
end
0.upto(@header.length - 1) do |counter|
- @doc[@header[counter]] = row[counter] rescue ''
+ if row.length > counter
+ @doc[@header[counter]] = row[counter]
+ else
+ @doc[@header[counter]] = ''
+ end
end
@file << JSON.dump(@doc)
end
- def close
+ def footer
@file << ']'
end
end
end
\ No newline at end of file