Sha256: 27abf4d95103677e4cc420ed67386ab5e76bc554152f6979648017ebeb0fae36

Contents?: true

Size: 1011 Bytes

Versions: 3

Compression:

Stored size: 1011 Bytes

Contents

module GS1
  module Barcode
    # Base class for a barcode.
    #
    class Base
      include Definitions

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

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

      def errors
        @errors ||= []
      end

      class << self
        def from_scan!(barcode, separator: DEFAULT_SEPARATOR)
          new(scan_to_params!(barcode, separator: separator))
        end

        def from_scan(barcode, separator: DEFAULT_SEPARATOR)
          new(scan_to_params(barcode, separator: separator))
        end

        def scan_to_params!(barcode, separator: DEFAULT_SEPARATOR)
          Tokenizer.new(barcode, separator: separator).to_params!
        end

        def scan_to_params(barcode, separator: DEFAULT_SEPARATOR)
          Tokenizer.new(barcode, separator: separator).to_params
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gs1-0.1.5 lib/gs1/barcode/base.rb
gs1-0.1.3 lib/gs1/barcode/base.rb
gs1-0.1.2 lib/gs1/barcode/base.rb