Sha256: 4de364d974d91ebd051968e940f05e38394e3490089a2f81d4b1f185afcb8dfc

Contents?: true

Size: 578 Bytes

Versions: 14

Compression:

Stored size: 578 Bytes

Contents

# frozen_string_literal: true

class Valvat
  module Checksum
    class LT < Base
      def check_digit
        base_checksum    = sum_with(0) % 11
        shifted_checksum = sum_with(2) % 11

        [base_checksum, shifted_checksum, 0].find { |checksum| checksum % 11 != 10 }
      end

      private

      def sum_with(offset)
        sum_figures_by do |digit, index|
          multi_digit_multiplier = figures.size - index + offset
          digit * (multi_digit_multiplier > 9 ? multi_digit_multiplier % 9 : multi_digit_multiplier)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
valvat-1.4.4 lib/valvat/checksum/lt.rb
valvat-1.4.3 lib/valvat/checksum/lt.rb
valvat-1.4.2 lib/valvat/checksum/lt.rb
valvat-1.4.1 lib/valvat/checksum/lt.rb
valvat-1.4.0 lib/valvat/checksum/lt.rb
valvat-1.3.0 lib/valvat/checksum/lt.rb
valvat-1.2.1 lib/valvat/checksum/lt.rb
valvat-1.2.0 lib/valvat/checksum/lt.rb
valvat-1.1.5 lib/valvat/checksum/lt.rb
valvat-1.1.4 lib/valvat/checksum/lt.rb
valvat-1.1.3 lib/valvat/checksum/lt.rb
valvat-1.1.2 lib/valvat/checksum/lt.rb
valvat-1.1.1 lib/valvat/checksum/lt.rb
valvat-1.1.0 lib/valvat/checksum/lt.rb