Class: Nervion::StreamParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsers = {}) ⇒ StreamParser

Returns a new instance of StreamParser.



8
9
10
11
12
# File 'lib/nervion/stream_parser.rb', line 8

def initialize(parsers = {})
  @http_parser = parsers[:http_parser] || Http::Parser.new
  @json_parser = parsers[:json_parser] || Yajl::Parser.new(symbolize_keys: true)
  @http_parser.on_body = method(:process)
end

Instance Attribute Details

#http_parserObject (readonly)

Returns the value of attribute http_parser.



6
7
8
# File 'lib/nervion/stream_parser.rb', line 6

def http_parser
  @http_parser
end

#json_parserObject (readonly)

Returns the value of attribute json_parser.



6
7
8
# File 'lib/nervion/stream_parser.rb', line 6

def json_parser
  @json_parser
end

Instance Method Details

#<<(http_stream) ⇒ Object



18
19
20
# File 'lib/nervion/stream_parser.rb', line 18

def <<(http_stream)
  @http_parser << http_stream
end

#on_json_parsed=(callback) ⇒ Object



14
15
16
# File 'lib/nervion/stream_parser.rb', line 14

def on_json_parsed=(callback)
  @json_parser.on_parse_complete = callback
end

#reset!Object



22
23
24
# File 'lib/nervion/stream_parser.rb', line 22

def reset!
  @http_parser.reset!
end