Sha256: 947689df0d148b9d25949bb57e8776734cbb3303edec28b0f870cbe73aac7923

Contents?: true

Size: 392 Bytes

Versions: 3

Compression:

Stored size: 392 Bytes

Contents

module GS1
  module Validations
    # Ensures correct check digit validation.
    #
    module CheckDigitValidation
      def validate_check_digit
        errors << 'Check digit mismatch' unless valid_check_digit?
      end

      def valid_check_digit?
        GS1::CheckDigitCalculator.with_sequence(data[0..-2]) == data
      rescue ArgumentError
        false
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gs1-0.1.2 lib/gs1/validations/check_digit_validation.rb
gs1-0.1.1 lib/gs1/validations/check_digit_validation.rb
gs1-0.1.0 lib/gs1/validations/check_digit_validation.rb