Class: Complicode::Generators::VerificationDigits

Inherits:
Object
  • Object
show all
Defined in:
lib/complicode/generators/verification_digits.rb

Constant Summary collapse

DIGITS_COUNT =
5
ITERATIONS =
2

Class Method Summary collapse

Class Method Details

.call(invoice) ⇒ String

Parameters:

Returns:

  • (String)

11
12
13
14
15
16
17
18
19
20
# File 'lib/complicode/generators/verification_digits.rb', line 11

def self.call(invoice)
  ITERATIONS.times do
    %i[number nit issue_date amount]
      .each { |attribute| invoice.append_checksum_digit_to(attribute) }
  end

  sum = invoice.sum
  DIGITS_COUNT.times { sum = Verhoeff.checksum_of(sum) }
  sum.to_s[-DIGITS_COUNT..-1]
end