Sha256: 54289dee97fd8e0416009ad640452d2d6d8ed7f3bd58efe657ca4cee5d29b7e7
Contents?: true
Size: 751 Bytes
Versions: 16
Compression:
Stored size: 751 Bytes
Contents
module Iban class Validator # public because it's used in `Ibanizator.calculate_iban` def sanitize_input(input) input.to_s.chomp.gsub(/\s+/,"") end private 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 def valid_checksum?(iban) number_representation = integerize(reorder(iban)) number_representation % 97 == 1 end def reorder(iban) "#{iban[4..-1]}#{iban[0..3]}" end def integerize(iban) iban.gsub(/[A-Z]/) do |match| match.ord - 'A'.ord + 10 end.to_i end end end
Version data entries
16 entries across 16 versions & 1 rubygems