module GS1::Definitions::ClassMethods

Adding defintion class methods.

Constants

DEFINITIONS

Attributes

definitions[R]

Public Instance Methods

allowed_lengths() click to toggle source
# File lib/gs1/definitions.rb, line 87
def allowed_lengths
  lengths[:allowed]
end
barcode_length() click to toggle source
# File lib/gs1/definitions.rb, line 79
def barcode_length
  lengths[:barcode]
end
barcode_max_length() click to toggle source
# File lib/gs1/definitions.rb, line 83
def barcode_max_length
  lengths[:max_barcode]
end
define(key, options = {}) click to toggle source
# File lib/gs1/definitions.rb, line 20
def define(key, options = {})
  raise UnknownDefinition, "#{key} is not a valid definition" unless DEFINITIONS.include?(key)

  @definitions ||= {}

  definitions[key] = send("normalize_#{key}_options", options)
end
lengths() click to toggle source
# File lib/gs1/definitions.rb, line 91
def lengths
  definitions[:length] || raise(MissingLengthDefinition)
end
normalize_check_digit_options(_options) click to toggle source

Currently no support for options.

# File lib/gs1/definitions.rb, line 29
def normalize_check_digit_options(_options)
  {}
end
normalize_date_month_based_options(_options) click to toggle source

Currently no support for options.

# File lib/gs1/definitions.rb, line 39
def normalize_date_month_based_options(_options)
  {}
end
normalize_date_options(_options) click to toggle source

Currently no support for options.

# File lib/gs1/definitions.rb, line 34
def normalize_date_options(_options)
  {}
end
normalize_length_options(options) click to toggle source

Defaults barcode length to allowed length if not explicitly defined, only if there is one significant allowed.

# File lib/gs1/definitions.rb, line 50
def normalize_length_options(options)
  options[:allowed] = normalize_multiple_option(options[:allowed] || options[:barcode])
  options[:barcode] = normalize_singlural_option(options[:barcode])
  options[:max_barcode] = options[:allowed]&.last

  options
end
normalize_multiple_option(option_value) click to toggle source
# File lib/gs1/definitions.rb, line 58
def normalize_multiple_option(option_value)
  case option_value
  when nil then nil
  when Range then option_value.to_a
  when Array then option_value
  else [option_value]
  end
end
normalize_separator_options(_options) click to toggle source

Boolean value

# File lib/gs1/definitions.rb, line 44
def normalize_separator_options(_options)
  true
end
normalize_singlural_option(option_value) click to toggle source
# File lib/gs1/definitions.rb, line 67
def normalize_singlural_option(option_value)
  return unless option_value

  raise InvalidDefinitionType unless option_value.is_a?(Numeric)

  option_value
end
separator?() click to toggle source
# File lib/gs1/definitions.rb, line 75
def separator?
  definitions[:separator]
end