Class: Outbanker::StatementLine
- Inherits:
-
Object
- Object
- Outbanker::StatementLine
show all
- Includes:
- MoneyStringParser
- Defined in:
- lib/outbanker/statement_line.rb
Overview
this is a representation of one line in an outbank csv statement with translated, parsed attributes (cents, date, etc.).
Constant Summary
collapse
- ATTRIBUTE_MAPPING =
{
:currency => "Währung",
:amount => "Betrag",
:booked_on => "Buchungstag",
:valuta_on => "Valuta-Datum",
:recipient => "Empfänger/Auftraggeber",
:bank_code => "Bankleitzahl",
:account_number => "Kontonummer",
:description => "Verwendungszweck",
:category => "Kategorie"
}
Instance Method Summary
collapse
#to_cents
Constructor Details
Returns a new instance of StatementLine.
25
26
27
|
# File 'lib/outbanker/statement_line.rb', line 25
def initialize(csv_row)
@row = csv_row
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(arg) ⇒ Object
63
64
65
66
|
# File 'lib/outbanker/statement_line.rb', line 63
def method_missing(arg)
super unless ATTRIBUTE_MAPPING.keys.include?(arg)
@row.send(:[], ATTRIBUTE_MAPPING[arg])
end
|
Instance Method Details
#amount ⇒ Object
29
30
31
|
# File 'lib/outbanker/statement_line.rb', line 29
def amount
to_cents(@row['Betrag'])
end
|
#booked_on ⇒ Object
33
34
35
|
# File 'lib/outbanker/statement_line.rb', line 33
def booked_on
Date.parse(@row['Buchungstag'])
end
|
#category ⇒ Object
55
56
57
|
# File 'lib/outbanker/statement_line.rb', line 55
def category
[nil, ''].include?(@row['Kategorie']) ? nil : @row['Kategorie']
end
|
#charged? ⇒ Boolean
37
38
39
40
|
# File 'lib/outbanker/statement_line.rb', line 37
def charged?
@row['Buchungstext'] != "Nicht abgerechnet"
end
|
#description ⇒ Object
46
47
48
|
# File 'lib/outbanker/statement_line.rb', line 46
def description
@row['Verwendungszweck'].to_s.gsub(/\s+/, ' ')
end
|
#payee ⇒ Object
50
51
52
53
|
# File 'lib/outbanker/statement_line.rb', line 50
def payee
desc_lines = @row['Verwendungszweck'].split(" ").reject { |row| row =~ /\A\s*\Z/ }.map { |row| row.strip }
desc_lines[1] || desc_lines[0] || nil
end
|
#prebooking? ⇒ Boolean
59
60
61
|
# File 'lib/outbanker/statement_line.rb', line 59
def prebooking?
@row['Vormerkung'] == 'Ja'
end
|
#to_s ⇒ Object
73
74
75
|
# File 'lib/outbanker/statement_line.rb', line 73
def to_s
"Buchung vom: #{booked_on}, Betrag: #{amount}, Beschreibung: #{description}"
end
|
#unique_id ⇒ Object
68
69
70
71
|
# File 'lib/outbanker/statement_line.rb', line 68
def unique_id
unique_string = [amount, booked_on, description].join('-')
Digest::MD5.hexdigest(unique_string)
end
|
#valuta_on ⇒ Object
42
43
44
|
# File 'lib/outbanker/statement_line.rb', line 42
def valuta_on
Date.parse(@row['Valuta-Datum'])
end
|