Class: Gtiny::GTIN

Inherits:
Encoding show all
Defined in:
lib/gtiny/gtin.rb

Overview

Any of GTIN 8, 12, 13, and 14 may be used in an ITF-14 or GS1-128, as long as they are formatted in 14 digits.

A GTIN may be encoded in EAN/UPC, ITF-14, GS1-128, GS1 DataBar, and GS1 DataMatrix. The GTIN may also be encoded in EPC scheme for RFID tags or in QR Code and Data Matrix when using GS1 Digital Link URI.

Direct Known Subclasses

GTIN12, GTIN13, GTIN14, GTIN8

Instance Method Summary collapse

Methods inherited from Encoding

#initialize, matches?, normalize, regex, #to_s, #type, #zeroes?

Constructor Details

This class inherits a constructor from Gtiny::Encoding

Instance Method Details

#check_digitObject



18
19
20
# File 'lib/gtiny/gtin.rb', line 18

def check_digit
  string[-1]
end

#company_prefix_and_item_referenceObject



22
23
24
# File 'lib/gtiny/gtin.rb', line 22

def company_prefix_and_item_reference
  string[0..-2]
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/gtiny/gtin.rb', line 14

def valid?
  self.class.regex.match?(string) && valid_check_digit?
end