Sha256: de48463c95a3eb221f8abf1b2d2b57107eacb60b0627e83f99904f6549fe2062

Contents?: true

Size: 431 Bytes

Versions: 6

Compression:

Stored size: 431 Bytes

Contents

module BrDocuments
  module Commons
    module Mod14
      def generate_check_digit(values, weights)
        sum = reduce_weights(values, weights)
        mod = sum % 11
        mod = (11 - mod)
        mod < 10 ? mod : (mod - 10)
      end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
br_documents-0.2.5 lib/br_documents/commons/mod14.rb
br_documents-0.2.4 lib/br_documents/commons/mod14.rb
br_documents-0.2.3 lib/br_documents/commons/mod14.rb
br_documents-0.2.2 lib/br_documents/commons/mod14.rb
br_documents-0.2.1 lib/br_documents/commons/mod14.rb
br_documents-0.2.0 lib/br_documents/commons/mod14.rb