lib/docparser/output.rb in docparser-0.0.1 vs lib/docparser/output.rb in docparser-0.1.0

- old
+ new

@@ -9,10 +9,12 @@ def initialize(filename: filename) @rowcount = 0 @filename = filename raise 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 end # Stores the header def header=(row) @@ -28,10 +30,13 @@ # Closes output and IO def close footer @file.close unless @file.closed? + @logger.info "Finished writing" + size = File.size(@filename) / 1024.0 + @logger.info sprintf("%s: %d rows, %.2f KiB", @filename, rowcount, size) end # Called after the file is opened def open_file # do nothing @@ -42,21 +47,16 @@ # do nothing end # Called when a row is added def write_row(row) - raise 'No row writer defined' + raise NotImplementedError.new('No row writer defined') end # Called before closing the file def footer end + end - # Displays information about the output - # @return [String] containing number of rows and file size - def summary - "%s:\t%d rows, %9.2f KiB" % [@filename, - @rowcount, - File.size(@filename) / 1024.0] - end + class MissingHeaderException < StandardError end end \ No newline at end of file