Class: Luhnar
- Inherits:
-
Object
- Object
- Luhnar
- Defined in:
- lib/luhnar.rb,
lib/luhnar/version.rb
Constant Summary collapse
- VERSION =
"1.0.1"
Class Method Summary collapse
-
.compute(number) ⇒ Object
returns checkdigit for number as integer.
Class Method Details
.compute(number) ⇒ Object
returns checkdigit for number as integer
6 7 8 9 10 11 12 13 14 |
# File 'lib/luhnar.rb', line 6 def self.compute number p = true -number.to_s.chars.to_a.reverse.inject(0) do |s,c| d = c.to_i d *= 2 if p p = !p s + d + d/10 end % 10 end |