Module: GS1::Definitions::ClassMethods
- Defined in:
- lib/gs1/definitions.rb
Overview
Adding defintion class methods.
Constant Summary collapse
- DEFINITIONS =
%i[check_digit date date_month_based length separator].freeze
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
Instance Method Summary collapse
- #allowed_lengths ⇒ Object
- #barcode_length ⇒ Object
- #barcode_max_length ⇒ Object
- #define(key, options = {}) ⇒ Object
- #lengths ⇒ Object
-
#normalize_check_digit_options(_options) ⇒ Object
Currently no support for options.
-
#normalize_date_month_based_options(_options) ⇒ Object
Currently no support for options.
-
#normalize_date_options(_options) ⇒ Object
Currently no support for options.
-
#normalize_length_options(options) ⇒ Object
Defaults barcode length to allowed length if not explicitly defined, only if there is one significant allowed.
- #normalize_multiple_option(option_value) ⇒ Object
-
#normalize_separator_options(_options) ⇒ Object
Boolean value.
- #normalize_singlural_option(option_value) ⇒ Object
- #separator? ⇒ Boolean
Instance Attribute Details
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
16 17 18 |
# File 'lib/gs1/definitions.rb', line 16 def definitions @definitions end |
Instance Method Details
#allowed_lengths ⇒ Object
87 88 89 |
# File 'lib/gs1/definitions.rb', line 87 def allowed_lengths lengths[:allowed] end |
#barcode_length ⇒ Object
79 80 81 |
# File 'lib/gs1/definitions.rb', line 79 def lengths[:barcode] end |
#barcode_max_length ⇒ Object
83 84 85 |
# File 'lib/gs1/definitions.rb', line 83 def lengths[:max_barcode] end |
#define(key, options = {}) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/gs1/definitions.rb', line 20 def define(key, = {}) raise UnknownDefinition, "#{key} is not a valid definition" unless DEFINITIONS.include?(key) @definitions ||= {} definitions[key] = send("normalize_#{key}_options", ) end |
#lengths ⇒ Object
91 92 93 |
# File 'lib/gs1/definitions.rb', line 91 def lengths definitions[:length] || raise(MissingLengthDefinition) end |
#normalize_check_digit_options(_options) ⇒ Object
Currently no support for options.
29 30 31 |
# File 'lib/gs1/definitions.rb', line 29 def () {} end |
#normalize_date_month_based_options(_options) ⇒ Object
Currently no support for options.
39 40 41 |
# File 'lib/gs1/definitions.rb', line 39 def () {} end |
#normalize_date_options(_options) ⇒ Object
Currently no support for options.
34 35 36 |
# File 'lib/gs1/definitions.rb', line 34 def () {} end |
#normalize_length_options(options) ⇒ Object
Defaults barcode length to allowed length if not explicitly defined, only if there is one significant allowed.
50 51 52 53 54 55 56 |
# File 'lib/gs1/definitions.rb', line 50 def () [:allowed] = normalize_multiple_option([:allowed] || [:barcode]) [:barcode] = normalize_singlural_option([:barcode]) [:max_barcode] = [:allowed]&.last end |
#normalize_multiple_option(option_value) ⇒ Object
58 59 60 61 62 63 64 65 |
# 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) ⇒ Object
Boolean value
44 45 46 |
# File 'lib/gs1/definitions.rb', line 44 def () true end |
#normalize_singlural_option(option_value) ⇒ Object
67 68 69 70 71 72 73 |
# 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? ⇒ Boolean
75 76 77 |
# File 'lib/gs1/definitions.rb', line 75 def separator? definitions[:separator] end |