Sha256: 1bd96badcac11e70475f0db80e7ce4fdabadf42248b8935f20481241eb905125

Contents?: true

Size: 965 Bytes

Versions: 1

Compression:

Stored size: 965 Bytes

Contents

module MT940Structured::Parsers::Rabobank
  class TransactionParser
    include MT940Structured::Parsers::DateParser, Types

    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.contra_account = number
        transaction.contra_account_owner = name.strip
        transaction
      else
        raise line_61
      end
    end

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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zilverline-mt940-2.0 lib/mt940_structured/parsers/rabobank/transaction_parser.rb