class Cmxl::Fields::StatementDetails

Public Class Methods

parse(line) click to toggle source
Calls superclass method Cmxl::Field::parse
# File lib/cmxl/fields/statement_details.rb, line 8
def parse(line)
  # remove line breaks as they are allowed via documentation but not needed for data-parsing
  super line.delete("\n")
end

Public Instance Methods

bic() click to toggle source
# File lib/cmxl/fields/statement_details.rb, line 45
def bic
  sub_fields['30']
end
description() click to toggle source
# File lib/cmxl/fields/statement_details.rb, line 22
def description
  sub_fields['00'] || data['details']
end
iban() click to toggle source
# File lib/cmxl/fields/statement_details.rb, line 53
def iban
  sub_fields['38'] || sub_fields['31']
end
information() click to toggle source
# File lib/cmxl/fields/statement_details.rb, line 26
def information
  info = (20..29).to_a.collect { |i| sub_fields[i.to_s] }.join('')
  info.empty? ? description : info
end
name() click to toggle source
# File lib/cmxl/fields/statement_details.rb, line 49
def name
  [sub_fields['32'], sub_fields['33']].compact.join(' ')
end
primanota() click to toggle source
# File lib/cmxl/fields/statement_details.rb, line 41
def primanota
  sub_fields['10']
end
sepa() click to toggle source
# File lib/cmxl/fields/statement_details.rb, line 31
def sepa
  if information =~ /([A-Z]{4})\+/
    Hash[
      *information.split(/([A-Z]{4})\+/)[1..-1].tap { |info| info << '' if info.size.odd? }
    ]
  else
    {}
  end
end
sub_fields() click to toggle source
# File lib/cmxl/fields/statement_details.rb, line 14
def sub_fields
  @sub_fields ||= if data['details'] =~ /#{Regexp.escape(data['seperator'])}(\d{2})/
                    Hash[data['details'].scan(/#{Regexp.escape(data['seperator'])}(\d{2})([^#{Regexp.escape(data['seperator'])}]*)/)]
                  else
                    {}
    end
end
to_h() click to toggle source
# File lib/cmxl/fields/statement_details.rb, line 57
def to_h
  {
    'bic' => bic,
    'iban' => iban,
    'name' => name,
    'sepa' => sepa,
    'information' => information,
    'description' => description,
    'sub_fields' => sub_fields,
    'transaction_code' => transaction_code,
    'primanota' => primanota,
    'details' => details
  }
end