Sha256: 0d30a9e9b6b48260bd9f6c5f096f572c2869cae6d19161292d1c1db81c72a4c2
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
require 'csv' require 'datev/header' require 'datev/booking' module Datev class Export CSV_OPTIONS = { :col_sep => ';', :encoding => 'windows-1252' } DEFAULT_HEADER_ATTRIBUTES = { 'DATEV-Format-KZ' => 'EXTF', 'Versionsnummer' => 510, 'Datenkategorie' => 21, 'Formatname' => 'Buchungsstapel', 'Formatversion' => 7, 'Erzeugt am' => Time.now, 'Sachkontenlänge' => 4, 'Bezeichnung' => 'Buchungen', 'Buchungstyp' => 1, 'WKZ' => 'EUR' } def initialize(header_attributes) @header = Header.new DEFAULT_HEADER_ATTRIBUTES.merge(header_attributes) @rows = [] end def <<(booking) raise ArgumentError.new('Param must be a Datev::Booking instance') unless booking.is_a?(Booking) @rows << booking end def to_s CSV.generate(CSV_OPTIONS) do |csv| write(csv) end end def to_file(filename) CSV.open(filename, 'wb', CSV_OPTIONS) do |csv| write(csv) end end private def write(csv) csv << @header.to_a csv << Booking.fields.map(&:name) @rows.each do |row| csv << row.to_a end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
datev-0.1.1 | lib/datev/export.rb |