Class: Valvat::Checksum::HR

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

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



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/valvat/checksum/hr.rb', line 6

def check_digit
  product = 10
  sum     = 0

  figures.each do |figure|
    sum = (figure + product) % 10
    sum = 10 if sum.zero?
    product = (2 * sum) % 11
  end

  (10 - ((product - 1) % 10)) % 10
end