Module: VerificadorBoletoBr::Calculus::Module11

Included in:
Slip::Arrecadation::CodeAssembly, Slip::Arrecadation::Validity, Slip::Bank::CodeAssembly, Slip::Bank::Validity
Defined in:
lib/verificador_boleto_br/calculus/module11.rb

Instance Method Summary collapse

Instance Method Details

#modulo11(str) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/verificador_boleto_br/calculus/module11.rb', line 4

def modulo11(str)
  peso = 2
  soma = 0

  str = str.chars.reverse

  str.each do |char|
    soma += char.to_i * peso
    peso = peso == 9 ? 2 : peso + 1
  end
  dv = soma % 11
  return 0 if dv == 0 || dv == 1

  return 1 if dv == 10

  11 - dv
end