Class: Lightstreamer::StreamBuffer
- Inherits:
-
Object
- Object
- Lightstreamer::StreamBuffer
- Defined in:
- lib/lightstreamer/stream_buffer.rb
Overview
Helper class used by StreamConnection that takes an incoming stream of ASCII data and yields back individual lines as they become complete.
Instance Method Summary collapse
-
#initialize ⇒ StreamBuffer
constructor
A new instance of StreamBuffer.
-
#process(data) {|line| ... } ⇒ Object
Appends a new piece of ASCII data to this buffer and yields back any lines that are now complete.
Constructor Details
#initialize ⇒ StreamBuffer
Returns a new instance of StreamBuffer.
7 8 9 |
# File 'lib/lightstreamer/stream_buffer.rb', line 7 def initialize @buffer = '' end |
Instance Method Details
#process(data) {|line| ... } ⇒ Object
Appends a new piece of ASCII data to this buffer and yields back any lines that are now complete.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lightstreamer/stream_buffer.rb', line 16 def process(data) @buffer << data lines = @buffer.split "\n" @buffer = @buffer.end_with?("\n") ? '' : lines.pop lines.each do |line| yield line.strip end end |