Module: BrDocuments::Commons::Mod11

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

Instance Method Summary collapse

Instance Method Details

#generate_check_digit(values, weights) ⇒ Object



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

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

#reduce_weights(values, weights) ⇒ Object



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

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