Class: VerificadorBoletoBr::Slip::Arrecadation::CodeAssembly

Inherits:
Object
  • Object
show all
Includes:
Calculus::Module10, Calculus::Module11
Defined in:
lib/verificador_boleto_br/slip/arrecadation/code_assembly.rb

Instance Method Summary collapse

Methods included from Calculus::Module11

#modulo11

Methods included from Calculus::Module10

#modulo10

Constructor Details

#initialize(code) ⇒ CodeAssembly

Returns a new instance of CodeAssembly.



9
10
11
# File 'lib/verificador_boleto_br/slip/arrecadation/code_assembly.rb', line 9

def initialize(code)
  @code = code
end

Instance Method Details

#bacen_moduleObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/verificador_boleto_br/slip/arrecadation/code_assembly.rb', line 29

def bacen_module
  case treated_code[2]
  when '6'
    'modulo10'
  when '7'
    'modulo10'
  when '8'
    'modulo11'
  when '9'
    'modulo11'
  end
end

#digitable_lineObject



21
22
23
24
25
26
27
# File 'lib/verificador_boleto_br/slip/arrecadation/code_assembly.rb', line 21

def digitable_line
  result = ""
  treated_group.each do |group|
    result += group + send(bacen_module, group).to_s
  end
  result
end

#treated_codeObject



17
18
19
# File 'lib/verificador_boleto_br/slip/arrecadation/code_assembly.rb', line 17

def treated_code
  treated_group.map {|partial| partial << "0" }.join
end

#treated_groupObject



13
14
15
# File 'lib/verificador_boleto_br/slip/arrecadation/code_assembly.rb', line 13

def treated_group
  @code.scan(/.{1,11}/m)
end