Class: Gtiny::GTIN14

Inherits:
GTIN show all
Defined in:
lib/gtiny/gtin14.rb

Overview

GTIN-14: Cannot be used in EAN/UPC barcodes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GTIN

#check_digit, #valid?

Methods inherited from Encoding

#initialize, matches?, normalize, #to_s, #valid?, #zeroes?

Constructor Details

This class inherits a constructor from Gtiny::Encoding

Class Method Details

.regexObject



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_referenceObject



24
25
26
# File 'lib/gtiny/gtin14.rb', line 24

def company_prefix_and_item_reference
  string[1..-2]
end

#indicator_digitObject

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_indicatorObject

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

#typeObject



13
14
15
# File 'lib/gtiny/gtin14.rb', line 13

def type
  "GTIN-14"
end