Class: CNPJ::VerifierDigit
- Inherits:
-
Object
- Object
- CNPJ::VerifierDigit
- Defined in:
- lib/cnpj/verifier_digit.rb
Class Method Summary collapse
Class Method Details
.generate(numbers) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/cnpj/verifier_digit.rb', line 5 def self.generate(numbers) index = 2 sum = numbers.reverse.reduce(0) do |buffer, number| (buffer + (number * index)).tap do index = index == 9 ? 2 : index + 1 end end mod = sum % 11 mod < 2 ? 0 : 11 - mod end |