Class: Datev::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/datev/export.rb

Constant Summary collapse

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.utc,
  'Sachkontenlänge' => 4,
  'Bezeichnung'     => 'Buchungen',
  'Buchungstyp'     => 1,
  'WKZ'             => 'EUR'
}

Instance Method Summary collapse

Constructor Details

#initialize(header_attributes) ⇒ Export

Returns a new instance of Export.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File 'lib/datev/export.rb', line 22

def initialize(header_attributes)
  raise ArgumentError.new('Hash required') unless header_attributes.is_a?(Hash)

  @header = Header.new DEFAULT_HEADER_ATTRIBUTES.merge(header_attributes)
  @rows = []
end

Instance Method Details

#<<(attributes) ⇒ Object



29
30
31
# File 'lib/datev/export.rb', line 29

def <<(attributes)
  @rows << Datev::Booking.new(attributes)
end

#to_file(filename) ⇒ Object



39
40
41
42
43
# File 'lib/datev/export.rb', line 39

def to_file(filename)
  CSV.open(filename, 'wb', CSV_OPTIONS) do |csv|
    write(csv)
  end
end

#to_s ⇒ Object



33
34
35
36
37
# File 'lib/datev/export.rb', line 33

def to_s
  CSV.generate(CSV_OPTIONS) do |csv|
    write(csv)
  end
end