Sha256: 6e3c4a6a7684c07791714afcfaac0606666a8267e30165323a4d6169cb420b86

Contents?: true

Size: 319 Bytes

Versions: 3

Compression:

Stored size: 319 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.sum % 11
      mod < 2 ? 0 : 11 - mod
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cpf_cnpj-1.0.1 lib/cpf/verifier_digit.rb
cpf_cnpj-1.0.0 lib/cpf/verifier_digit.rb
cpf_cnpj-0.6.0 lib/cpf/verifier_digit.rb