module GS1::Extensions::Date

Extension for a GS1 date. Ensures correct formating and validation.

Public Class Methods

included(base) click to toggle source
# File lib/gs1/extensions/date.rb, line 8
def self.included(base)
  base.define :date
  base.define :length, barcode: 6
end
new(date) click to toggle source
Calls superclass method
# File lib/gs1/extensions/date.rb, line 13
def initialize(date)
  if date.respond_to?(:strftime)
    super(date.strftime('%y%m%d'))
  else
    super(date)
  end
end

Public Instance Methods

to_date() click to toggle source
# File lib/gs1/extensions/date.rb, line 21
def to_date
  ::Date.parse(data)
end