Class: Cuker::CsvFile

Inherits:
AbstractFile show all
Defined in:
lib/cuker/helpers/writers/csv_writer.rb

Overview

Instance Attribute Summary

Attributes inherited from AbstractFile

#name, #rows

Attributes included from LoggerSetup

#log

Instance Method Summary collapse

Methods inherited from AbstractFile

#current_row, #finishup

Methods included from LoggerSetup

#init_logger, reset_appender_log_levels

Constructor Details

#initialize(file_name) ⇒ CsvFile

Returns a new instance of CsvFile.



44
45
46
47
48
49
# File 'lib/cuker/helpers/writers/csv_writer.rb', line 44

def initialize file_name
  super file_name
  @log.debug "Making new #{self.class} => #{file_name}"
  @csv_sheet = CSV.open(file_name, "wb")
  @csv_sheet.close
end

Instance Method Details

#add_row(row_ary) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/cuker/helpers/writers/csv_writer.rb', line 51

def add_row row_ary
  super row_ary
  @log.warn "argument not an array.. instead is a '#{row_ary.class}' -> '#{row_ary}'" unless row_ary.is_a? Array
  CSV.open(@name, "ab") do |csv|
    csv << row_ary
  end
end

#read_rowsObject

Returns ary of rows.

Returns:

  • ary of rows



60
61
62
# File 'lib/cuker/helpers/writers/csv_writer.rb', line 60

def read_rows
  @rows = CSV.read(@name)
end