Class: ABNF::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/abnf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s, full = nil, pos = 0) ⇒ Stream

Returns a new instance of Stream.



33
34
35
36
37
# File 'lib/abnf.rb', line 33

def initialize(s, full = nil, pos = 0)
  @s = s
  @full = full.nil? ? s : full
  @pos = pos
end

Instance Attribute Details

#posObject (readonly)

Returns the value of attribute pos.



31
32
33
# File 'lib/abnf.rb', line 31

def pos
  @pos
end

Instance Method Details

#clip(start) ⇒ Object



47
48
49
# File 'lib/abnf.rb', line 47

def clip(start)
  @full[start...@pos]
end

#firstObject



39
40
41
# File 'lib/abnf.rb', line 39

def first
  @s[0].ord if @s[0]
end

#restObject



43
44
45
# File 'lib/abnf.rb', line 43

def rest
  Stream.new(@s[1..-1], @full, @pos + 1)
end