Module: ModFunctions

Defined in:
lib/validator_ie/core/mod_functions.rb

Class Method Summary collapse

Class Method Details

.matrix_weight(size, final, reverse) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/validator_ie/core/mod_functions.rb', line 3

def self.matrix_weight(size, final, reverse)
  count = initial = (reverse ? 1 : 0)
  matrix = []    
  (size).times do |i|
    count += 1
    count = count > final ? initial + 1 : count 
    matrix << count
  end
  return (reverse ? matrix.reverse : matrix)
end

.sumX(number, at, final, reverse = true, matrix = nil) ⇒ Object



14
15
16
17
18
# File 'lib/validator_ie/core/mod_functions.rb', line 14

def self.sumX(number, at, final, reverse = true, matrix = nil)
  weight = matrix.nil? ? matrix_weight(at + 1, final, reverse) : matrix
  return 0 if at > weight.size - 1
  sum = number[0..at].map.with_index { |v, k| v * weight[k]}.reduce(:+)
end