Class: GS1::Record

Inherits:
Object
  • Object
show all
Includes:
Definitions, Validations
Defined in:
lib/gs1/record.rb

Overview

Base class for a GS1 record.

Direct Known Subclasses

Batch, Content, ExpirationDate, GTIN, SSCC, SerialNumber

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validations

included

Methods included from Definitions

included

Constructor Details

#initialize(data) ⇒ Record

Returns a new instance of Record.



10
11
12
# File 'lib/gs1/record.rb', line 10

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/gs1/record.rb', line 8

def data
  @data
end

Class Method Details

.aiObject



25
26
27
# File 'lib/gs1/record.rb', line 25

def ai
  self::AI
end

.generatedObject



18
# File 'lib/gs1/record.rb', line 18

def generated = false

.inherited(subclass) ⇒ Object



20
21
22
23
# File 'lib/gs1/record.rb', line 20

def inherited(subclass)
  super
  descendants << subclass
end

.underscore_nameObject



29
30
31
32
33
34
35
36
37
# File 'lib/gs1/record.rb', line 29

def underscore_name
  name.split('::')
      .last
      .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      .gsub(/([a-z\d])([A-Z])/, '\1_\2')
      .tr('-', '_')
      .downcase
      .to_sym
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
57
# File 'lib/gs1/record.rb', line 54

def ==(other)
  self.class.equal?(other.class) &&
    to_s.eql?(other.to_s)
end

#aiObject



40
41
42
# File 'lib/gs1/record.rb', line 40

def ai
  self.class.ai
end

#to_aiObject



48
49
50
51
52
# File 'lib/gs1/record.rb', line 48

def to_ai
  return unless to_s

  ai + to_s
end

#to_sObject



44
45
46
# File 'lib/gs1/record.rb', line 44

def to_s
  data&.to_s
end