lib/docparser/output.rb in docparser-0.2.2 vs lib/docparser/output.rb in docparser-0.2.3
- old
+ new
@@ -1,10 +1,10 @@
module DocParser
# The Output base class.
# All Output classes inherit from this one.
class Output
- attr_reader :rowcount
+ attr_reader :rowcount, :filename
# Creates a new output
#
# You can assign the output to the Parser so it automatically writes all
# data to the file you want.
@@ -17,13 +17,15 @@
# @see CSVOutput
# @see HTMLOutput
# @see YAMLOutput
# @see XLSXOutput
# @see MultiOutput
- def initialize(filename: filename)
+ def initialize(filename: nil, uniq: false)
@rowcount = 0
@filename = filename
+ @uniq = uniq
+ @uniqarr = []
fail ArgumentError, 'Please specify a filename' if filename.empty?
@file = open filename, 'w'
classname = self.class.name.split('::').last
@logger = Log4r::Logger.new("docparser::output::#{classname}")
open_file
@@ -35,12 +37,14 @@
header
end
# Adds a row
def add_row(row)
+ return if @uniq && @uniqarr.include?(row.hash)
@rowcount += 1
write_row row
+ @uniqarr << row.hash
end
# Closes output and IO
def close
footer
@@ -59,10 +63,10 @@
def header
# do nothing
end
# Called when a row is added
- def write_row(row)
+ def write_row(_row)
fail NotImplementedError, 'No row writer defined'
end
# Called before closing the file
def footer