Class: Valvat::Checksum::MT

Inherits:
Base
  • Object
show all
Defined in:
lib/valvat/checksum/mt.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



8
9
10
11
12
13
14
15
# File 'lib/valvat/checksum/mt.rb', line 8

def check_digit
  multipliers = [9, 8, 7, 6, 4, 3]

  sum = sum_figures_by { |digit, index| digit * multipliers[index] }

  supposed_checksum = 37 - (sum % 37)
  supposed_checksum.zero? ? 37 : supposed_checksum
end