Class: Buble::Streaming::SSEParser
- Inherits:
-
Object
- Object
- Buble::Streaming::SSEParser
- Defined in:
- lib/buble/streaming.rb
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize ⇒ SSEParser
constructor
A new instance of SSEParser.
- #push_line(line) ⇒ Object
Constructor Details
#initialize ⇒ SSEParser
Returns a new instance of SSEParser.
10 11 12 13 |
# File 'lib/buble/streaming.rb', line 10 def initialize @event = nil @data = [] end |
Instance Method Details
#finish ⇒ Object
32 33 34 |
# File 'lib/buble/streaming.rb', line 32 def finish finish_event end |
#push_line(line) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/buble/streaming.rb', line 15 def push_line(line) line = line.to_s.sub(/\r\z/, '') return finish_event if line.empty? return nil if line.start_with?(':') field, value = line.split(':', 2) value = value ? value.sub(/\A /, '') : '' case field when 'event' @event = value when 'data' @data << value end nil end |