Sha256: 0b71f32cff26b42b35434d123e94a2b6f5bfd68ba6e9f879ad236e0598e017b1

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

module MT940Structured::Parsers::Rabobank
  class StructuredTransactionParser
    include MT940Structured::Parsers::DateParser,
            Types,
            MT940Structured::Parsers::StructuredDescriptionParser,
            MT940Structured::Parsers::IbanSupport


    def parse_transaction(line_61)
      valuta_date = parse_date(line_61[4, 6])
      sign = line_61[10, 1] == 'D' ? -1 : 1
      amount = sign * line_61[11, 15].gsub(',', '.').to_f
      transaction_type = human_readable_type(line_61[27, 3])
      parts = line_61.split(/\s/)
      potential_iban = parts.size > 1 ? parts.last.gsub(/^[P]{0,1}0*/, '').strip : nil
      number = potential_iban.nil? ? "NONREF" : iban_to_account(potential_iban)
      contra_account_iban = iban?(potential_iban) ? potential_iban : nil
      MT940::Transaction.new(amount: amount,
                             type: transaction_type,
                             date: valuta_date,
                             contra_account_iban: contra_account_iban,
                             contra_account: number.strip)

    end

    def enrich_transaction(transaction, line_86)
      transaction.description = line_86[4..-1]
      description_parts = transaction.description.split('/')
      transaction.description = parse_description_after_tag description_parts, "REMI"
      if transaction.description == ''
        structured_betalingskenmerk = parse_description_after_tag(description_parts, "CDTRREF")
        transaction.description = "BETALINGSKENMERK #{structured_betalingskenmerk}" unless structured_betalingskenmerk == ''
      end
      transaction.contra_account_owner = description_parts[description_parts.index { |part| part == "NAME" } + 1].gsub(/\r|\n/, '') if description_parts.index { |part| part == "NAME" }
      transaction.description.strip!
    end

  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

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