Class: MT940Structured::Parsers::Rabobank::TransactionParser

Inherits:
Object
  • Object
show all
Includes:
DateParser, Types
Defined in:
lib/mt940_structured/parsers/rabobank/transaction_parser.rb

Constant Summary

Constants included from Types

MT940Structured::Parsers::Rabobank::Types::MAPPING

Instance Method Summary collapse

Methods included from DateParser

#parse_date

Methods included from Types

#human_readable_type

Instance Method Details

#enrich_transaction(transaction, line_86) ⇒ Object



22
23
24
25
26
# File 'lib/mt940_structured/parsers/rabobank/transaction_parser.rb', line 22

def enrich_transaction(transaction, line_86)
  if line_86.match(/^:86:(.*)$/)
    transaction.description = [transaction.description, $1].join(" ").strip
  end
end

#parse_transaction(line_61) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mt940_structured/parsers/rabobank/transaction_parser.rb', line 5

def parse_transaction(line_61)
  if line_61.match(/^:61:(\d{6})(C|D)(\d+),(\d{0,2})N(.{3})([P|\d]\d{9}|NONREF)\s*(.+)?$/)
    sign = $2 == 'D' ? -1 : 1
    transaction = MT940::Transaction.new(:amount => sign * ($3 + '.' + $4).to_f)
    transaction.type = human_readable_type($5)
    transaction.date = parse_date($1)
    number = $6.strip
    name = $7 || ""
    number = number.gsub(/\D/, '').gsub(/^0+/, '') unless number == 'NONREF'
    transaction. = number
    transaction. = name.strip
    transaction
  else
    raise line_61
  end
end