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

Version Path
ibanizator-0.4.15 lib/iban/validator.rb
ibanizator-0.4.14 lib/iban/validator.rb
ibanizator-0.4.13 lib/iban/validator.rb
ibanizator-0.4.12 lib/iban/validator.rb
ibanizator-0.4.11 lib/iban/validator.rb
ibanizator-0.4.10 lib/iban/validator.rb
ibanizator-0.4.9 lib/iban/validator.rb
ibanizator-0.4.8 lib/iban/validator.rb
ibanizator-0.4.7 lib/iban/validator.rb
ibanizator-0.4.6 lib/iban/validator.rb
ibanizator-0.4.5 lib/iban/validator.rb
ibanizator-0.4.4 lib/iban/validator.rb
ibanizator-0.4.3 lib/iban/validator.rb
ibanizator-0.4.2 lib/iban/validator.rb
ibanizator-0.4.1 lib/iban/validator.rb
ibanizator-0.4.0 lib/iban/validator.rb