Sha256: db15347905913ff791d29cb20ca1e6cde09a52bfc3643ff3d5619e6499e33b92
Contents?: true
Size: 589 Bytes
Versions: 8
Compression:
Stored size: 589 Bytes
Contents
module GS1 module Extensions # Extension for a GS1 GTIN. Ensures correct formating and validation. # module GTIN 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 # Default to GTIN-14 since it is the most common format. def to_s return unless data to_gtin_14 end end end end
Version data entries
8 entries across 8 versions & 1 rubygems