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



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

def ai
  self::AI
end

.inherited(subclass) ⇒ Object



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

def inherited(subclass)
  descendants << subclass
end

.underscore_nameObject



26
27
28
29
30
31
32
33
34
# File 'lib/gs1/record.rb', line 26

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



51
52
53
54
# File 'lib/gs1/record.rb', line 51

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

#aiObject



37
38
39
# File 'lib/gs1/record.rb', line 37

def ai
  self.class.ai
end

#to_aiObject



45
46
47
48
49
# File 'lib/gs1/record.rb', line 45

def to_ai
  return unless to_s

  ai + to_s
end

#to_sObject



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

def to_s
  data&.to_s
end