class Iban::Validator

Public Instance Methods

sanitize_input(input) click to toggle source

public because it's used in `Ibanizator.calculate_iban`

# File lib/iban/validator.rb, line 4
def sanitize_input(input)
  input.to_s.chomp.gsub(/\s+/,"")
end

Private Instance Methods

integerize(iban) click to toggle source
# File lib/iban/validator.rb, line 25
def integerize(iban)
  iban.gsub(/[A-Z]/) do |match|
    match.ord - 'A'.ord + 10
  end.to_i
end
reorder(iban) click to toggle source
# File lib/iban/validator.rb, line 21
def reorder(iban)
  "#{iban[4..-1]}#{iban[0..3]}"
end
valid_checksum?(iban) click to toggle source
# File lib/iban/validator.rb, line 16
def valid_checksum?(iban)
  number_representation = integerize(reorder(iban))
  number_representation % 97 == 1
end
valid_length?(iban) click to toggle source
# File lib/iban/validator.rb, line 10
def valid_length?(iban)
  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 == Ibanizator::Iban::LENGTHS[country_code]
end