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
49 50 51 52 53 54 55 56 |
# File 'lib/ibandit/iban_splitter.rb', line 49 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
29 30 31 32 33 34 35 36 |
# File 'lib/ibandit/iban_splitter.rb', line 29 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
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ibandit/iban_splitter.rb', line 38 def self.branch_code_from(iban) unless decomposable?(iban) && structure(iban)[:branch_code_length] > 0 return end iban.slice( structure(iban)[:branch_code_position] - 1, structure(iban)[:branch_code_length] ) end |
.check_digits_from(iban) ⇒ Object
23 24 25 26 27 |
# File 'lib/ibandit/iban_splitter.rb', line 23 def self.check_digits_from(iban) return unless decomposable?(iban) iban.slice(2, 2) end |
.country_code_from(iban) ⇒ Object
Component parts #
17 18 19 20 21 |
# File 'lib/ibandit/iban_splitter.rb', line 17 def self.country_code_from(iban) return if iban.nil? || iban.empty? iban.slice(0, 2) end |
.decomposable?(iban) ⇒ Boolean
58 59 60 |
# File 'lib/ibandit/iban_splitter.rb', line 58 def self.decomposable?(iban) structure(iban) && iban.length == structure(iban)[:total_length] end |
.split(iban) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/ibandit/iban_splitter.rb', line 3 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
62 63 64 |
# File 'lib/ibandit/iban_splitter.rb', line 62 def self.structure(iban) Ibandit.structures[country_code_from(iban)] end |