module Codecal::Modulo

Public Instance Methods

simple_code_calculate(int_array) click to toggle source
# File lib/lib/modulo.rb, line 19
def simple_code_calculate(int_array)
  code = int_array.reverse.each_with_index.inject(0) do |count, (i, index)| 
    count += i * ( index < @@MODULO_WEIGHT.size ? 
                    @@MODULO_WEIGHT.reverse[index + 1].to_i : 
                    ( index + 1 ).times.inject(1) { |c| c *= 3 } % @@MODULO_NUMBER
                  )
  end
  symbol = convert_to_symbol(code % @@MODULO_NUMBER)
  (int_array.join + symbol).to_i.to_s
end

Private Instance Methods

convert_to_number(symbol) click to toggle source
# File lib/lib/modulo.rb, line 41
def convert_to_number(symbol)
  @@SEVENTEEN_SYMBOL.find_index(symbol)
end
convert_to_symbol(number) click to toggle source

def simple_code_calculate(array)

code = array.reverse.each_with_index.inject(0){|count, (i, index)| count += i*( index < 11 ? @@MODULO_WEIGHT.reverse[index + 1] : (index+1).times.inject(1) {|c| c *= 3} % 7 ) }
return (array.join + ( code % 7 ).to_s).to_i.to_s

end

# File lib/lib/modulo.rb, line 37
def convert_to_symbol(number)
  @@SEVENTEEN_SYMBOL[number]
end