class Ibandit::PseudoIBANSplitter
Public Class Methods
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 5 def initialize(pseudo_iban) @pseudo_iban = pseudo_iban end
Public Instance Methods
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 19 def country_code @pseudo_iban.slice(0, 2) end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 9 def split { country_code: country_code, check_digits: check_digits, bank_code: bank_code, branch_code: branch_code, account_number: account_number, } end
Private Instance Methods
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 41 def account_number return unless country_code_valid? remove_leading_padding( @pseudo_iban.slice(account_number_start_index, @pseudo_iban.length), ) end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 64 def account_number_start_index branch_code_start_index + structure.fetch(:pseudo_iban_branch_code_length) end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 29 def bank_code return unless country_code_valid? pseudo_iban_part(bank_code_start_index, :pseudo_iban_bank_code_length) end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 56 def bank_code_start_index 4 end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 35 def branch_code return unless country_code_valid? pseudo_iban_part(branch_code_start_index, :pseudo_iban_branch_code_length) end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 60 def branch_code_start_index bank_code_start_index + structure.fetch(:pseudo_iban_bank_code_length) end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 25 def check_digits @pseudo_iban.slice(2, 2) end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 68 def country_code_valid? Constants::PSEUDO_IBAN_COUNTRY_CODES.include?(country_code) end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 72 def padding_character Constants::PSEUDO_IBAN_PADDING_CHARACTER_FOR[country_code] end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 49 def pseudo_iban_part(start_index, length_key) length = structure.fetch(length_key) return if length&.zero? remove_leading_padding(@pseudo_iban.slice(start_index, length)) end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 80 def remove_leading_padding(input) return unless padding_character input.gsub(/\A#{padding_character}+/, "") end
Source
# File lib/ibandit/pseudo_iban_splitter.rb, line 76 def structure Ibandit.structures[country_code] end