Module: GS1::Extensions::GTIN
Overview
Extension for a GS1 GTIN. Ensures correct formating and validation.
Class Method Summary collapse
Instance Method Summary collapse
-
#to_s ⇒ Object
Default to GTIN-14 since it is the most common format.
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/gs1/extensions/gtin.rb', line 6 def self.included(base) base.define :check_digit base.define :length, allowed: [8, 12, 13, 14].freeze, barcode: 14 base.allowed_lengths.each do |length| define_method "to_gtin_#{length}" do data.to_s.rjust(length, '0') end end end |
Instance Method Details
#to_s ⇒ Object
Default to GTIN-14 since it is the most common format.
18 19 20 21 22 |
# File 'lib/gs1/extensions/gtin.rb', line 18 def to_s return unless data to_gtin_14 end |