Class: Ibanizator
- Inherits:
-
Object
show all
- Defined in:
- lib/ibanizator.rb,
lib/ibanizator/bank.rb,
lib/ibanizator/iban.rb,
lib/ibanizator/bank_db.rb,
lib/ibanizator/iban/invalid.rb,
lib/ibanizator/iban/lengths.rb,
lib/ibanizator/iban/validator.rb,
lib/ibanizator/iban/extended_data.rb,
lib/ibanizator/iban/extended_data/de.rb
Defined Under Namespace
Classes: Bank, BankDb, Iban
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.bank_db ⇒ Object
10
11
12
|
# File 'lib/ibanizator.rb', line 10
def self.bank_db
@bank_db ||= BankDb.new
end
|
.iban_from_string(string) ⇒ Object
14
15
16
|
# File 'lib/ibanizator.rb', line 14
def self.iban_from_string(string)
Iban.from_string(string)
end
|
Instance Method Details
#calculate_checksum(bank_code, account_number, country_code_num) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/ibanizator.rb', line 41
def calculate_checksum(bank_code, account_number, country_code_num)
x = (bank_code + account_number + country_code_num + '00').to_i % 97
checksum = (98 - x).to_s
checksum.length == 1 ? checksum.insert(0, '0') : checksum
end
|
#calculate_iban(options) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/ibanizator.rb', line 18
def calculate_iban(options)
options[:account_number] = options[:account_number].to_s.gsub(/\s+/, '')
options[:bank_code] = options[:bank_code].to_s.gsub(/\s+/, '')
while options[:account_number].size < 10 do
options[:account_number] = options[:account_number].rjust(10, '0')
end
country_code_num = character_to_digit options[:country_code].to_s
checksum = calculate_checksum options[:bank_code], options[:account_number], country_code_num
options[:country_code].to_s.upcase + checksum + options[:bank_code] + options[:account_number]
end
|
#character_to_digit(char) ⇒ Object
37
38
39
|
# File 'lib/ibanizator.rb', line 37
def character_to_digit(char)
char.upcase.split('').inject('') { |code, c| code + (c.ord - 55).to_s }
end
|