class Mod11
Constants
- VERSION
- WEIGHT
Attributes
initial_value[RW]
Public Class Methods
new(initial_value)
click to toggle source
# File lib/mod11.rb, line 10 def initialize(initial_value) @initial_value = initial_value end
Public Instance Methods
check_digit()
click to toggle source
# File lib/mod11.rb, line 18 def check_digit sum = 0 initial_value.to_s.reverse.chars.each_with_index do |char, i| sum += char.to_i * WEIGHT[i] end remainder = sum % 11 case remainder when 0 then remainder when 1 then nil else 11 - remainder end end
full_value()
click to toggle source
# File lib/mod11.rb, line 14 def full_value initial_value.to_s + check_digit.to_s end