Class: Norma43::Models::Account::SpanishIban

Inherits:
Object
  • Object
show all
Defined in:
lib/norma43/models/account/spanish_iban.rb

Constant Summary collapse

COUNTRY_CODE =
"ES"
BANK_CODE_RANGE =
BRANCH_CODE_RANGE = 0..9999
MAX_BANK_CODE_SIZE =
MAX_BRANCH_CODE_SIZE = 4
ACCOUNT_NUMBER_RANGE =
0..9_999_999_999
IBAN_MODULUS =
97
IBAN_FORMAT_STRING =
"%{country_code}%<checksum_number>02d%{ccc}"
CCC_MODULUS =
11
CCC_FORMAT_STRING =
"%<bank_code>04d%<branch_code>04d%<checksum_number>02d%<account_number>010d"
CCC_WEIGHTS =

Sorted by order of magnitude: units, tens, hundreds, etc.

[6, 3, 7, 9, 10, 5, 8, 4, 2, 1].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bank_code:, branch_code:, account_number:) ⇒ SpanishIban

Returns a new instance of SpanishIban.



27
28
29
30
31
32
33
34
# File 'lib/norma43/models/account/spanish_iban.rb', line 27

def initialize(bank_code:, branch_code:, account_number:)
  @bank_code, @branch_code, @account_number =
    if self.class.valid_numbers?(bank_code, branch_code, )
      [bank_code, branch_code, ]
    else
      [nil, nil, nil]
    end
end

Class Method Details

.from_account(account) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/norma43/models/account/spanish_iban.rb', line 17

def self.()
  return nil unless valid_numbers?(.bank_code, .branch_code, .)

  new(
    bank_code: .bank_code,
    branch_code: .branch_code,
    account_number: .
  ).to_s
end

Instance Method Details

#to_sObject



36
37
38
39
40
# File 'lib/norma43/models/account/spanish_iban.rb', line 36

def to_s
  return "" if [bank_code, branch_code, ].any?(nil)

  iban
end