Sha256: fca03329646884041d3e5d5d78b7c49c904dd832aa1da1a6b738975a5c7e933c

Contents?: true

Size: 326 Bytes

Versions: 2

Compression:

Stored size: 326 Bytes

Contents

# frozen_string_literal: true

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

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

      mod = multiplied.reduce(:+) % 11
      mod < 2 ? 0 : 11 - mod
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cpf_cnpj-0.5.0 lib/cpf/verifier_digit.rb
cpf_cnpj-0.4.1 lib/cpf/verifier_digit.rb