Module: BrDocuments::Commons::Mod11

Included in:
BrDocuments::CnpjCpf::Document, IE::AP, IE::BA, IE::MG, IE::Pattern1, IE::Pattern2, IE::RN, IE::RO, IE::SP
Defined in:
lib/br_documents/commons/mod11.rb

Instance Method Summary collapse

Instance Method Details

#generate_digital_check(values, weights) ⇒ Object



5
6
7
8
9
# File 'lib/br_documents/commons/mod11.rb', line 5

def generate_digital_check(values, weights)
  sum = reduce_weights(values, weights)
  mod = sum % 11
  mod < 2 ? 0 : (11 - mod)
end

#reduce_weights(values, weights) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/br_documents/commons/mod11.rb', line 11

def reduce_weights(values, weights)
  sum = 0
  weights.each_index do |i|
    sum += weights[i] * values[i].to_i
  end
  sum
end