Class: CPF::VerifierDigit

Inherits:
Object
  • Object
show all
Defined in:
lib/cpf/verifier_digit.rb

Class Method Summary collapse

Class Method Details

.generate(numbers) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/cpf/verifier_digit.rb', line 5

def self.generate(numbers)
  modulus = numbers.size + 1

  multiplied = numbers.map.each_with_index do |number, index|
    number * (modulus - index)
  end

  mod = multiplied.sum % 11
  mod < 2 ? 0 : 11 - mod
end