Module: GS1::Definitions::ClassMethods
- Defined in:
- lib/gs1/definitions.rb
Overview
Adding defintion class methods.
Constant Summary collapse
- DEFINITIONS =
i[check_digit date length].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_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_singlural_option(option_value) ⇒ Object
Instance Attribute Details
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
15 16 17 |
# File 'lib/gs1/definitions.rb', line 15 def definitions @definitions end |
Instance Method Details
#allowed_lengths ⇒ Object
71 72 73 |
# File 'lib/gs1/definitions.rb', line 71 def allowed_lengths lengths[:allowed] end |
#barcode_length ⇒ Object
63 64 65 |
# File 'lib/gs1/definitions.rb', line 63 def lengths[:barcode] end |
#barcode_max_length ⇒ Object
67 68 69 |
# File 'lib/gs1/definitions.rb', line 67 def lengths[:max_barcode] end |
#define(key, options = {}) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/gs1/definitions.rb', line 19 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
75 76 77 |
# File 'lib/gs1/definitions.rb', line 75 def lengths definitions[:length] || raise(MissingLengthDefinition) end |
#normalize_check_digit_options(_options) ⇒ Object
Currently no support for options.
28 29 30 |
# File 'lib/gs1/definitions.rb', line 28 def () {} end |
#normalize_date_options(_options) ⇒ Object
Currently no support for options.
33 34 35 |
# File 'lib/gs1/definitions.rb', line 33 def () {} end |
#normalize_length_options(options) ⇒ Object
Defaults barcode length to allowed length if not explicitly defined, only if there is one significant allowed.
39 40 41 42 43 44 45 |
# File 'lib/gs1/definitions.rb', line 39 def () [:allowed] = normalize_multiple_option([:allowed]) [:barcode] = normalize_singlural_option([:barcode]) [:max_barcode] = normalize_singlural_option([:barcode] || [:allowed]) end |
#normalize_multiple_option(option_value) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/gs1/definitions.rb', line 47 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_singlural_option(option_value) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/gs1/definitions.rb', line 56 def normalize_singlural_option(option_value) case option_value when Array then option_value.last else option_value end end |