Class: Valvat::Checksum::DE

Inherits:
Base
  • Object
show all
Defined in:
lib/valvat/checksum/de.rb

Constant Summary collapse

M =
10
N =
11

Instance Attribute Summary

Attributes inherited from Base

#vat

Instance Method Summary collapse

Methods inherited from Base

check_digit_length, #initialize, #validate

Constructor Details

This class inherits a constructor from Valvat::Checksum::Base

Instance Method Details

#check_digitObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/valvat/checksum/de.rb', line 9

def check_digit
  prod = M
  figures.each do |fig|
    sum = (prod + fig).modulo(M)
    sum = M if sum.zero?
    prod = (2 * sum).modulo(N)
  end
  chk = N - prod
  chk == 10 ? 0 : chk
end