Sha256: 33dc3cabb633b300442230b6b033385545872c9d1689504bf8abeb795a70d380
Contents?: true
Size: 406 Bytes
Versions: 14
Compression:
Stored size: 406 Bytes
Contents
module LuhnChecker # This method implements Luhn algorythm. # Details about it's work may be founded here: http://en.wikipedia.org/wiki/Luhn_Algorithm def self.valid?(s) value = s.gsub(/\D/, '').reverse sum = i = 0 value.each_char do |ch| n = ch.to_i n *= 2 if i.odd? n = 1 + (n - 10) if n >= 10 sum += n i += 1 end (sum % 10).zero? end end
Version data entries
14 entries across 14 versions & 1 rubygems