Class: MT940Structured::Parsers::BankStatementParser
- Inherits:
-
Object
- Object
- MT940Structured::Parsers::BankStatementParser
- Includes:
- BalanceParser, DateParser, IbanSupport
- Defined in:
- lib/mt940_structured/parsers/bank_statement_parser.rb
Constant Summary
Constants included from IbanSupport
Instance Attribute Summary collapse
-
#bank_statement ⇒ Object
readonly
Returns the value of attribute bank_statement.
Instance Method Summary collapse
-
#initialize(bank, transaction_parsers, lines) ⇒ BankStatementParser
constructor
A new instance of BankStatementParser.
- #parse_line_25(line) ⇒ Object
- #parse_line_60(line) ⇒ Object
- #parse_line_61(line_61) ⇒ Object
- #parse_line_62(line) ⇒ Object
- #parse_line_86(line) ⇒ Object
Methods included from DateParser
Methods included from BalanceParser
Methods included from IbanSupport
Constructor Details
#initialize(bank, transaction_parsers, lines) ⇒ BankStatementParser
Returns a new instance of BankStatementParser.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mt940_structured/parsers/bank_statement_parser.rb', line 6 def initialize(bank, transaction_parsers, lines) @bank = bank @transaction_parsers = transaction_parsers @bank_statement = MT940::BankStatement.new([]) lines.each do |line| if line.match /^:(\d{2})(F|C|M)?:/ parse_method = "parse_line_#{$1}".to_sym send(parse_method, line) if respond_to? parse_method else raise "nyi '#{$1}' - line #{line}" end end end |
Instance Attribute Details
#bank_statement ⇒ Object (readonly)
Returns the value of attribute bank_statement.
4 5 6 |
# File 'lib/mt940_structured/parsers/bank_statement_parser.rb', line 4 def bank_statement @bank_statement end |
Instance Method Details
#parse_line_25(line) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mt940_structured/parsers/bank_statement_parser.rb', line 20 def parse_line_25(line) line.gsub!('.', '') case line when /^:\d{2}:NL/ @bank_statement.bank_account_iban = line[4, 18] @bank_statement.bank_account = iban_to_account(@bank_statement.bank_account_iban) @is_structured_format = true when /^:\d{2}:\D*(\d*)/ @bank_statement.bank_account = $1.gsub(/\D/, '').gsub(/^0+/, '') @is_structured_format = false else raise "Unknown format for tag 25: #{line}" end end |
#parse_line_60(line) ⇒ Object
35 36 37 |
# File 'lib/mt940_structured/parsers/bank_statement_parser.rb', line 35 def parse_line_60(line) @bank_statement.previous_balance = parse_balance(line) end |
#parse_line_61(line_61) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mt940_structured/parsers/bank_statement_parser.rb', line 39 def parse_line_61(line_61) @is_structured_format = @transaction_parsers.structured?(line_61) if @transaction_parsers.respond_to?(:structured?) @transaction_parser = @transaction_parsers.for_format @is_structured_format transaction = @transaction_parser.parse_transaction(line_61) transaction.bank_account = @bank_statement.bank_account transaction.bank_account_iban = @bank_statement.bank_account_iban transaction.currency = @bank_statement.previous_balance.currency transaction.bank = @bank @bank_statement.transactions << transaction end |
#parse_line_62(line) ⇒ Object
54 55 56 |
# File 'lib/mt940_structured/parsers/bank_statement_parser.rb', line 54 def parse_line_62(line) @bank_statement.new_balance = parse_balance(line) end |
#parse_line_86(line) ⇒ Object
50 51 52 |
# File 'lib/mt940_structured/parsers/bank_statement_parser.rb', line 50 def parse_line_86(line) @transaction_parser.enrich_transaction(@bank_statement.transactions.last, line) end |