Class: DTAUS::Datensatz
- Inherits:
-
Object
- Object
- DTAUS::Datensatz
- Defined in:
- lib/dtaus/datensatz.rb
Overview
Vollständiger DTA-Datensatz mit Header (A), Body © und Footer (E)
Instance Attribute Summary collapse
-
#auftraggeber_konto ⇒ Object
readonly
Returns the value of attribute auftraggeber_konto.
-
#ausfuehrungsdatum ⇒ Object
readonly
Returns the value of attribute ausfuehrungsdatum.
-
#buchungen ⇒ Object
readonly
Returns the value of attribute buchungen.
-
#positiv ⇒ Object
(also: #positiv?)
readonly
Returns the value of attribute positiv.
-
#transaktionstyp ⇒ Object
readonly
Returns the value of attribute transaktionstyp.
Instance Method Summary collapse
-
#add(_buchung) ⇒ Object
Eine Buchung zum Datensatz hinzufügen.
-
#initialize(_transaktionstyp, _auftraggeber_konto, _ausfuehrungsdatum = Time.now) ⇒ Datensatz
constructor
Vollständigen DTA-Datensatz erstellen.
-
#to_dta ⇒ Object
(also: #to_s)
DTA-Repräsentation dieses Datensatzes.
-
#to_file(filename = 'DTAUS0.TXT') ⇒ Object
Schreibt die DTAUS-Datei.
Constructor Details
#initialize(_transaktionstyp, _auftraggeber_konto, _ausfuehrungsdatum = Time.now) ⇒ Datensatz
Vollständigen DTA-Datensatz erstellen
Parameter:
_transaktionstyp
-
Art der Transaktionen (als :Symbol)
-
:lastschrift
für Lastschriften Kundenseitig -
:gutschrift
für Gutschriften Kundenseitig
-
_auftraggeber_konto
-
das DTAUS::Konto des Auftraggebers
_ausfuehrungsdatum
-
Ausführungsdatum des Datensatzes, optional, Default-Wert ist die aktuelle Zeit
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dtaus/datensatz.rb', line 21 def initialize(_transaktionstyp, _auftraggeber_konto, _ausfuehrungsdatum = Time.now) unless [:lastschrift, :gutschrift].include?(_transaktionstyp) raise DTAUSException.new("Transaktionstyp has to be one of [:lastschrift, :gutschrift]") end unless _auftraggeber_konto.is_a?(Konto) raise DTAUSException.new("Konto expected, got #{_auftraggeber_konto.class}") end unless _ausfuehrungsdatum.is_a?(Date) or _ausfuehrungsdatum.is_a?(Time) raise DTAUSException.new("Date or Time expected, got #{_ausfuehrungsdatum.class}") end @transaktionstyp = _transaktionstyp @auftraggeber_konto = _auftraggeber_konto @ausfuehrungsdatum = _ausfuehrungsdatum @buchungen = [] end |
Instance Attribute Details
#auftraggeber_konto ⇒ Object (readonly)
Returns the value of attribute auftraggeber_konto.
8 9 10 |
# File 'lib/dtaus/datensatz.rb', line 8 def auftraggeber_konto @auftraggeber_konto end |
#ausfuehrungsdatum ⇒ Object (readonly)
Returns the value of attribute ausfuehrungsdatum.
8 9 10 |
# File 'lib/dtaus/datensatz.rb', line 8 def ausfuehrungsdatum @ausfuehrungsdatum end |
#buchungen ⇒ Object (readonly)
Returns the value of attribute buchungen.
8 9 10 |
# File 'lib/dtaus/datensatz.rb', line 8 def buchungen @buchungen end |
#positiv ⇒ Object (readonly) Also known as: positiv?
Returns the value of attribute positiv.
8 9 10 |
# File 'lib/dtaus/datensatz.rb', line 8 def positiv @positiv end |
#transaktionstyp ⇒ Object (readonly)
Returns the value of attribute transaktionstyp.
8 9 10 |
# File 'lib/dtaus/datensatz.rb', line 8 def transaktionstyp @transaktionstyp end |
Instance Method Details
#add(_buchung) ⇒ Object
Eine Buchung zum Datensatz hinzufügen.
Es wird geprüft, ob das Vorzeichen identisch mit den bisherigen Vorzeichen ist.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dtaus/datensatz.rb', line 42 def add(_buchung) raise DTAUSException.new("Buchung expected, got #{_buchung.class}") unless _buchung.is_a?(Buchung) # Die erste Buchung bestimmt, ob alle Beträge positiv oder negativ sind. @positiv = _buchung.positiv? if @buchungen.empty? # Wirf Exception wenn Vorzeichen gemischt werden unless @positiv == _buchung.positiv? raise DTAUSException.new("Nicht erlaubter Vorzeichenwechsel! "+ "Buchung muss wie die vorherigen Buchungen #{positiv? ? 'positiv' : 'negativ'} sein!") end @buchungen << _buchung end |
#to_dta ⇒ Object Also known as: to_s
DTA-Repräsentation dieses Datensatzes
59 60 61 |
# File 'lib/dtaus/datensatz.rb', line 59 def to_dta DtaGenerator.new(self).to_dta end |
#to_file(filename = 'DTAUS0.TXT') ⇒ Object
Schreibt die DTAUS-Datei
Parameter:
filename
-
Name der zu schreibenden Datei; optional, Default-Wert ist
DTAUS0.TXT
69 70 71 72 73 |
# File 'lib/dtaus/datensatz.rb', line 69 def to_file(filename = 'DTAUS0.TXT') File.open(filename, 'w') do |file| file << to_dta end end |