class Ibanizator::Iban::Validator
Attributes
iban[R]
Public Class Methods
new(iban)
click to toggle source
# File lib/ibanizator/iban/validator.rb, line 6 def initialize(iban) @iban = iban.to_s end
Public Instance Methods
validate()
click to toggle source
# File lib/ibanizator/iban/validator.rb, line 10 def validate valid_length? && valid_checksum? end
Private Instance Methods
integerize(iban)
click to toggle source
# File lib/ibanizator/iban/validator.rb, line 31 def integerize(iban) iban.gsub(/[A-Z]/) { |match| match.ord - 'A'.ord + 10 }.to_i end
reorder(iban)
click to toggle source
# File lib/ibanizator/iban/validator.rb, line 27 def reorder(iban) "#{iban[4..-1]}#{iban[0..3]}" end
valid_checksum?()
click to toggle source
# File lib/ibanizator/iban/validator.rb, line 22 def valid_checksum? number_representation = integerize(reorder(iban)) number_representation % 97 == 1 end
valid_length?()
click to toggle source
# File lib/ibanizator/iban/validator.rb, line 16 def valid_length? return false if iban.length <= 4 # two digits for the country code and two for the checksum country_code = iban[0..1].upcase.to_sym iban.length == COUNTRY_CODES[country_code] end