Class: GS1::Barcode::Base

Inherits:
Object
  • Object
show all
Includes:
Definitions
Defined in:
lib/gs1/barcode/base.rb

Overview

Base class for a barcode.

Direct Known Subclasses

Healthcare

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Definitions

included

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
# File 'lib/gs1/barcode/base.rb', line 8

def initialize(options = {})
  @params_order = options.keys

  self.class.records.each do |record|
    data = options.fetch(record.underscore_name, nil)

    instance_variable_set("@#{record.underscore_name}", record.new(data))
  end
end

Class Method Details

.from_scan(barcode, separator: GS1.configuration.barcode_separator) ⇒ Object



27
28
29
# File 'lib/gs1/barcode/base.rb', line 27

def from_scan(barcode, separator: GS1.configuration.barcode_separator)
  new(scan_to_params(barcode, separator: separator))
end

.from_scan!(barcode, separator: GS1.configuration.barcode_separator) ⇒ Object



23
24
25
# File 'lib/gs1/barcode/base.rb', line 23

def from_scan!(barcode, separator: GS1.configuration.barcode_separator)
  new(scan_to_params!(barcode, separator: separator))
end

.scan_to_params(barcode, separator: GS1.configuration.barcode_separator) ⇒ Object



35
36
37
# File 'lib/gs1/barcode/base.rb', line 35

def scan_to_params(barcode, separator: GS1.configuration.barcode_separator)
  Tokenizer.new(barcode, separator: separator).to_params
end

.scan_to_params!(barcode, separator: GS1.configuration.barcode_separator) ⇒ Object



31
32
33
# File 'lib/gs1/barcode/base.rb', line 31

def scan_to_params!(barcode, separator: GS1.configuration.barcode_separator)
  Tokenizer.new(barcode, separator: separator).to_params!
end

Instance Method Details

#errorsObject



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

def errors
  @errors ||= []
end