class GS1::Barcode::Tokenizer
Class for parsing barcodes. Uses {Segment} for splitting up the individual parts.
Attributes
data[R]
params[R]
separator[R]
Public Class Methods
new(data, separator: GS1.configuration.barcode_separator)
click to toggle source
# File lib/gs1/barcode/tokenizer.rb, line 9 def initialize(data, separator: GS1.configuration.barcode_separator) @data = data @separator = separator @params = [] end
Public Instance Methods
to_params()
click to toggle source
# File lib/gs1/barcode/tokenizer.rb, line 15 def to_params @to_params ||= segment_to_params(data) end
to_params!()
click to toggle source
# File lib/gs1/barcode/tokenizer.rb, line 19 def to_params! @to_params ||= segment_to_params(data, true) end
Private Instance Methods
segment_from_input(input, bang) { |segment| ... }
click to toggle source
# File lib/gs1/barcode/tokenizer.rb, line 39 def segment_from_input(input, bang) Segment.new(input, separator: separator).tap do |segment| segment.validate! if bang yield segment if block_given? end end
segment_to_params(input, bang = false)
click to toggle source
# File lib/gs1/barcode/tokenizer.rb, line 25 def segment_to_params(input, bang = false) segment_from_input(input, bang) do |segment| next if segment.to_params.empty? params << segment.to_params next if segment.rest.empty? segment_to_params(segment.rest, bang) end params end