Sha256: 13aef131254ef591360512f96a60cef89d0494027f7c9b0b18aa91f329d013f5

Contents?: true

Size: 558 Bytes

Versions: 10

Compression:

Stored size: 558 Bytes

Contents

module GS1
  module Validations
    # Ensures correct length validation.
    #
    module LengthValidation
      def validate_length
        errors << 'Invalid length' unless valid_length?
      end

      def valid_length?
        return false unless data

        valid_barcode_length? || valid_allowed_length?
      end

      def valid_allowed_length?
        self.class.allowed_lengths.include?(data.size)
      end

      def valid_barcode_length?
        self.class.barcode_length == data.size if self.class.barcode_length
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gs1-1.1.0 lib/gs1/validations/length_validation.rb
gs1-1.0.0 lib/gs1/validations/length_validation.rb
gs1-0.1.8 lib/gs1/validations/length_validation.rb
gs1-0.1.7 lib/gs1/validations/length_validation.rb
gs1-0.1.6 lib/gs1/validations/length_validation.rb
gs1-0.1.5 lib/gs1/validations/length_validation.rb
gs1-0.1.3 lib/gs1/validations/length_validation.rb
gs1-0.1.2 lib/gs1/validations/length_validation.rb
gs1-0.1.1 lib/gs1/validations/length_validation.rb
gs1-0.1.0 lib/gs1/validations/length_validation.rb