Module: Ibandit::IBANSplitter
- Defined in:
- lib/ibandit/iban_splitter.rb
Class Method Summary collapse
- .account_number_from(iban) ⇒ Object
- .bank_code_from(iban) ⇒ Object
- .branch_code_from(iban) ⇒ Object
- .check_digits_from(iban) ⇒ Object
-
.country_code_from(iban) ⇒ Object
Component parts #.
- .decomposable?(iban) ⇒ Boolean
- .split(iban) ⇒ Object
- .structure(iban) ⇒ Object
Class Method Details
.account_number_from(iban) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/ibandit/iban_splitter.rb', line 50 def self.account_number_from(iban) return unless decomposable?(iban) iban.slice( structure(iban)[:account_number_position] - 1, structure(iban)[:account_number_length], ) end |
.bank_code_from(iban) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/ibandit/iban_splitter.rb', line 31 def self.bank_code_from(iban) return unless decomposable?(iban) iban.slice( structure(iban)[:bank_code_position] - 1, structure(iban)[:bank_code_length], ) end |
.branch_code_from(iban) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/ibandit/iban_splitter.rb', line 40 def self.branch_code_from(iban) return unless decomposable?(iban) && structure(iban)[:branch_code_length]&.positive? iban.slice( structure(iban)[:branch_code_position] - 1, structure(iban)[:branch_code_length], ) end |
.check_digits_from(iban) ⇒ Object
25 26 27 28 29 |
# File 'lib/ibandit/iban_splitter.rb', line 25 def self.check_digits_from(iban) return unless decomposable?(iban) iban.slice(2, 2) end |
.country_code_from(iban) ⇒ Object
Component parts #
19 20 21 22 23 |
# File 'lib/ibandit/iban_splitter.rb', line 19 def self.country_code_from(iban) return if iban.nil? || iban.empty? iban.slice(0, 2) end |
.decomposable?(iban) ⇒ Boolean
59 60 61 |
# File 'lib/ibandit/iban_splitter.rb', line 59 def self.decomposable?(iban) structure(iban) && iban.length == structure(iban)[:total_length] end |
.split(iban) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/ibandit/iban_splitter.rb', line 5 def self.split(iban) { country_code: country_code_from(iban), check_digits: check_digits_from(iban), bank_code: bank_code_from(iban), branch_code: branch_code_from(iban), account_number: account_number_from(iban), } end |
.structure(iban) ⇒ Object
63 64 65 |
# File 'lib/ibandit/iban_splitter.rb', line 63 def self.structure(iban) Ibandit.structures[country_code_from(iban)] end |