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
17
# File 'lib/gs1/barcode/base.rb', line 8

def initialize(options = {})
  options.each do |(attribute_name, data)|
    validate_attribute_data(attribute_name)
    validate_attribute_record(attribute_name) do |record|
      instance_variable_set("@#{attribute_name}", record.new(data))
    end
  end

  @params_order = options.to_h.keys
end

Class Method Details

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



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

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



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

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



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

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



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

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

Instance Method Details

#errorsObject



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

def errors
  @errors ||= Errors.new
end