Class: Teodoro::CNPJ::RaizSufixo::Numero

Inherits:
Object
  • Object
show all
Defined in:
lib/teodoro/cnpj.rb

Instance Method Summary collapse

Instance Method Details

#dvObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/teodoro/cnpj.rb', line 51

def dv
  string.chars
        .reverse
        .map(&:to_i)
        .map.with_index { |digito, indice| [digito, (indice % 8) + 2] }
        .sum { |digito, peso| digito * peso }
        .then { |r| 11 - (r % 11) }
        .then { |r| r >= 10 ? 0 : r }
        .to_s
end