Sha256: a51603809f05a178475ac63ddc08e39f69ce14690e0b0417036a925136189390

Contents?: true

Size: 956 Bytes

Versions: 3

Compression:

Stored size: 956 Bytes

Contents

class MT940::Triodos < MT940::Base

  private

  def parse_tag_86
    if @line.match(/^:86:000(.*)$/)
      processed_description = hashify_description($1)

      @transaction.contra_account = if sepa?(processed_description)
        processed_description['21']
      else
        processed_description['10'][/[^0+]\d*/]
      end

      @transaction.description = extract_description(processed_description)
    end
  end

  def bic_code?(text)
     MT940::BIC_CODES.values.include?(text)
  end

  def extract_description(text)
    identifier = sepa?(text) ? 22 : 20
    description = ''
    text.each do |k,v|
      description += v if k.to_i >= identifier && k.to_i < 30
    end
    description
  end

  def hashify_description(description)
    hash = {}
    description.split('>').compact.each do |slice|
      next if slice.empty?
      hash[slice[0..1]] = slice[2..-1]
    end
    hash
  end

  def sepa?(text)
    text['10'] == '0000000000'
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mt940-0.8.0 lib/mt940/banks/triodos.rb
mt940-0.7.1 lib/mt940/banks/triodos.rb
mt940-0.7.0 lib/mt940/banks/triodos.rb