Sha256: 57b5e68f887204b4db2f54838dc19dff251c0e5f9eb14c36f605648b92770bbd
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
require_relative 'abstract_writer' module Cuker class CsvWriter < AbstractWriter def initialize @ext = '.csv' super @log.debug "initing #{self.class}" end def write_title title_ary super title_ary @log.debug "csv write title" @active_file.add_row title_ary end def write_new_row row_ary super row_ary @log.debug "csv write row: #{row_ary}" @active_file.add_row row_ary end def make_new_sheet name @log.debug "csv make new sheet" #todo: dangit! handling this path naming properly file_name = "#{name.nil? ? super(name) : name}#{ext}" @book[file_name] = CsvFile.new file_name @active_file = @book[file_name] file_name end def make_new_file name path = super name make_new_sheet name end end require 'csv' # == CSV Sheet # extends sheet to give csv read/write-ability # {file:https://docs.ruby-lang.org/en/2.1.0/CSV.html CSV usage documentation} class CsvFile < AbstractFile def initialize file_name super file_name @log.info "Making new #{self.class} => #{file_name}" @csv_sheet = CSV.open(file_name, "wb") @csv_sheet.close end 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 # @return ary of rows def read_rows @rows = CSV.read(@name) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cuker-0.5.15 | lib/cuker/helpers/writers/csv_writer.rb |