Class: Outbanker::StatementLine

Inherits:
Object
  • Object
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

Methods included from MoneyStringParser

#to_cents

Constructor Details

#initialize(csv_row) ⇒ StatementLine

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

#amountObject



29
30
31
# File 'lib/outbanker/statement_line.rb', line 29

def amount
  to_cents(@row['Betrag'])
end

#booked_onObject



33
34
35
# File 'lib/outbanker/statement_line.rb', line 33

def booked_on
  Date.parse(@row['Buchungstag'])
end

#categoryObject



55
56
57
# File 'lib/outbanker/statement_line.rb', line 55

def category
  [nil, ''].include?(@row['Kategorie']) ? nil : @row['Kategorie']
end

#charged?Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/outbanker/statement_line.rb', line 37

def charged?
  # in different cases I get either "Abgerechnet" or "" when a line was charged.
  @row['Buchungstext'] != "Nicht abgerechnet"
end

#descriptionObject



46
47
48
# File 'lib/outbanker/statement_line.rb', line 46

def description
  @row['Verwendungszweck'].to_s.gsub(/\s+/, ' ')
end

#payeeObject



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

Returns:

  • (Boolean)


59
60
61
# File 'lib/outbanker/statement_line.rb', line 59

def prebooking?
  @row['Vormerkung'] == 'Ja'
end

#to_sObject



73
74
75
# File 'lib/outbanker/statement_line.rb', line 73

def to_s
  "Buchung vom: #{booked_on}, Betrag: #{amount}, Beschreibung: #{description}"
end

#unique_idObject



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_onObject



42
43
44
# File 'lib/outbanker/statement_line.rb', line 42

def valuta_on
  Date.parse(@row['Valuta-Datum'])
end