Sha256: d0ea3086b6da70f34a93de6c8b201e30f195ecead7505814e1fdd1fab957bc53

Contents?: true

Size: 432 Bytes

Versions: 21

Compression:

Stored size: 432 Bytes

Contents

# == CreditCardValidations Luhn
# simple class to validate Luhn numbers.
#
#   Luhn.valid? 4111111111111111
#
module CreditCardValidations
  class Luhn
    def self.valid?(number)
      s1 = s2 = 0
      number.to_s.reverse.chars.each_slice(2) do |odd, even|
        s1 += odd.to_i

        double = even.to_i * 2
        double -= 9 if double >= 10
        s2 += double
      end
      (s1 + s2) % 10 == 0
    end
  end
end  
  
  

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
credit_card_validations-7.0.0 lib/credit_card_validations/luhn.rb
credit_card_validations-6.3.0 lib/credit_card_validations/luhn.rb
credit_card_validations-6.1.0 lib/credit_card_validations/luhn.rb
credit_card_validations-6.0.0 lib/credit_card_validations/luhn.rb
credit_card_validations-5.0.0 lib/credit_card_validations/luhn.rb
credit_card_validations-4.1.0 lib/credit_card_validations/luhn.rb
credit_card_validations-4.0.0 lib/credit_card_validations/luhn.rb
credit_card_validations-3.5.1 lib/credit_card_validations/luhn.rb
credit_card_validations-3.5.0 lib/credit_card_validations/luhn.rb
cw_credit_card_validations-3.4.2 lib/credit_card_validations/luhn.rb
cw_credit_card_validations-3.4.1 lib/credit_card_validations/luhn.rb
cw_credit_card_validations-3.4.0 lib/credit_card_validations/luhn.rb
credit_card_validations-3.4.0 lib/credit_card_validations/luhn.rb
credit_card_validations-3.3.0 lib/credit_card_validations/luhn.rb
credit_card_validations-3.2.2 lib/credit_card_validations/luhn.rb
credit_card_validations-3.2.1 lib/credit_card_validations/luhn.rb
credit_card_validations-3.1.0 lib/credit_card_validations/luhn.rb
credit_card_validations-3.0.0 lib/credit_card_validations/luhn.rb
credit_card_validations-2.0.2 lib/credit_card_validations/luhn.rb
credit_card_validations-2.0.1 lib/credit_card_validations/luhn.rb