Class: Codabel::Type::AccountAndCurrency

Inherits:
Codabel::Type show all
Defined in:
lib/codabel/type/account_and_currency.rb

Instance Method Summary collapse

Methods inherited from Codabel::Type

#check!

Instance Method Details

#to_coda(value, length) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/codabel/type/account_and_currency.rb', line 4

def to_coda(value, length)
  check!(length == 37, "Expected length to be 37, got #{length}")
   = Model::Account.dress(value)

  case .structure
  when Model::Account::BELGIAN_BBAN
    str = .number.ljust(12, ' ')   # 12 N Belgian account number
    str << ' ' * 1                        #  1 AN blank
    str << .currency.ljust(3, ' ') #  3 AN ISO currency code or blank
    str << '0'                            #  1 N qualification code or blank
    str << 'BE'                           #  2 AN ISO country code or blank
    str << ' ' * 3                        #  3 AN blank spaces
    str << ' ' * 15                       #  15 AN extension zone or blank
  when Model::Account::FOREIGN_BBAN
    str = .number.ljust(34, ' ')   # 34 AN foreign account number
    str << .currency.ljust(3, ' ') #  3 AN ISO currency code of the account
  when Model::Account::BELGIAN_IBAN
    str = .number.ljust(31, ' ')   # 31 AN IBAN (Belgian number)
    str << ' ' * 3                        # 3 AN extension zone or blank
    str << .currency.ljust(3, ' ') # 3 AN ISO currency code of the account
  when Model::Account::FOREIGN_IBAN
    str = .number.ljust(34, ' ')   # 34 AN foreign account number
    str << .currency.ljust(3, ' ') #  3 AN ISO currency code of the account
  end
end