class Datev::Export
Constants
- CSV_OPTIONS
Attributes
header_class[RW]
row_class[RW]
Public Class Methods
new(header_attributes)
click to toggle source
# File lib/datev/export.rb, line 9 def initialize(header_attributes) @header = self.class.header_class.new(header_attributes) @rows = [] end
Public Instance Methods
<<(attributes)
click to toggle source
# File lib/datev/export.rb, line 14 def <<(attributes) @rows << self.class.row_class.new(attributes) end
to_file(filename)
click to toggle source
# File lib/datev/export.rb, line 29 def to_file(filename) File.open(filename, 'wb') do |file| file.write(to_s) end end
to_s()
click to toggle source
# File lib/datev/export.rb, line 18 def to_s string = to_csv_line(@header.output) << to_csv_line(self.class.row_class.fields.map(&:name)) @rows.each do |row| string << to_csv_line(row.output(@header)) end string.encode(CSV_OPTIONS[:encoding], invalid: :replace, undef: :replace, replace: ' ') end
Private Instance Methods
to_csv_line(data)
click to toggle source
# File lib/datev/export.rb, line 37 def to_csv_line(data) data.join(CSV_OPTIONS[:col_sep]) + "\r\n" end