Class: URITemplate::RFC6570::Tokenizer

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/uri_template/rfc6570.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, ops) ⇒ Tokenizer

Returns a new instance of Tokenizer.



211
212
213
214
# File 'lib/uri_template/rfc6570.rb', line 211

def initialize(source, ops)
  @source = source
  @operators = ops
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



209
210
211
# File 'lib/uri_template/rfc6570.rb', line 209

def source
  @source
end

Instance Method Details

#eachObject



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/uri_template/rfc6570.rb', line 216

def each
  scanner = StringScanner.new(@source)
  until scanner.eos?
    expression = scanner.scan(EXPRESSION)
    if expression
      vars = scanner[2].split(',').map{|name|
        match = VAR.match(name)
        # 1 = varname
        # 2 = explode
        # 3 = length
        [ match[1], match[2] == '*', match[3].to_i ]
      }
      yield @operators[scanner[1]].new(vars)
    else
      literal = scanner.scan(LITERAL)
      if literal
        yield(Literal.new(literal))
      else
        raise Invalid.new(@source,scanner.pos)
      end
    end
  end
end