class BankAccountTools::IBAN
Public Class Methods
new(code)
click to toggle source
# File lib/bank_account_tools/iban.rb, line 15 def initialize(code) @code = code.to_s.gsub(/\s+/, '').upcase end
valid?(code)
click to toggle source
# File lib/bank_account_tools/iban.rb, line 11 def self.valid?(code) new(code).valid? end
Public Instance Methods
bban()
click to toggle source
# File lib/bank_account_tools/iban.rb, line 27 def bban @bban ||= BBAN.new(country_code, @code[4..-1]) end
check_digits()
click to toggle source
# File lib/bank_account_tools/iban.rb, line 23 def check_digits @code[2..3] end
country_code()
click to toggle source
# File lib/bank_account_tools/iban.rb, line 19 def country_code @code[0..1] end
to_i()
click to toggle source
# File lib/bank_account_tools/iban.rb, line 39 def to_i "#{bban}#{country_code}#{check_digits}".each_char.map { |chr| chr.to_i(36) }.join.to_i end
to_s(formatted=false)
click to toggle source
# File lib/bank_account_tools/iban.rb, line 43 def to_s(formatted=false) formatted ? @code.gsub(/(.{4})/, '\1 ').strip : @code end
valid?()
click to toggle source
# File lib/bank_account_tools/iban.rb, line 31 def valid? valid_check_digits? && bban.valid? end
valid_check_digits?()
click to toggle source
# File lib/bank_account_tools/iban.rb, line 35 def valid_check_digits? to_i % 97 == 1 end