Class: Gtiny::GTIN14
Overview
GTIN-14: Cannot be used in EAN/UPC barcodes
Class Method Summary collapse
Instance Method Summary collapse
- #company_prefix_and_item_reference ⇒ Object
-
#indicator_digit ⇒ Object
Indicator digit indicates packagaing level.
-
#strip_indicator ⇒ Object
Returns a GTIN14 instance with the packaging indicator set to “0”.
- #type ⇒ Object
Methods inherited from GTIN
Methods inherited from Encoding
#initialize, matches?, normalize, #to_s, #valid?, #zeroes?
Constructor Details
This class inherits a constructor from Gtiny::Encoding
Class Method Details
.regex ⇒ Object
9 10 11 |
# File 'lib/gtiny/gtin14.rb', line 9 def self.regex /\A[0-9]{14}\z/ end |
Instance Method Details
#company_prefix_and_item_reference ⇒ Object
24 25 26 |
# File 'lib/gtiny/gtin14.rb', line 24 def company_prefix_and_item_reference string[1..-2] end |
#indicator_digit ⇒ Object
Indicator digit indicates packagaing level. -> A value of 0 indicates absence of information. -> A value of 9 indicates variable measure.
20 21 22 |
# File 'lib/gtiny/gtin14.rb', line 20 def indicator_digit string[0] end |
#strip_indicator ⇒ Object
Returns a GTIN14 instance with the packaging indicator set to “0”. This is useful for “normalizing” GTIN-14s, e.g. if you’re trying to detect the same product at various packaging levels.
31 32 33 34 35 36 37 38 |
# File 'lib/gtiny/gtin14.rb', line 31 def strip_indicator return self if indicator_digit == "0" gtin_sans_check = "0#{company_prefix_and_item_reference}" check_digit = CheckDigitCalculators.gs1(gtin_sans_check) GTIN14.new(gtin_sans_check + check_digit) end |
#type ⇒ Object
13 14 15 |
# File 'lib/gtiny/gtin14.rb', line 13 def type "GTIN-14" end |