Class: Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



6
7
8
9
# File 'lib/tunnels/parser.rb', line 6

def initialize
  @parser = Http::Parser.new
  @raw = ''
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



4
5
6
# File 'lib/tunnels/parser.rb', line 4

def raw
  @raw
end

Instance Method Details

#<<(data) ⇒ Object



11
12
13
14
# File 'lib/tunnels/parser.rb', line 11

def << data
  @raw << data
  @parser << data
end

#on_completeObject



16
17
18
19
20
21
# File 'lib/tunnels/parser.rb', line 16

def on_complete
  @parser.on_message_complete = proc do
    yield @raw
    reset
  end
end

#resetObject



23
24
25
26
# File 'lib/tunnels/parser.rb', line 23

def reset
  @parser.reset!
  @raw.respond_to?(:clear) ? @raw.clear : @raw = ''
end