Class: Lightstreamer::LineBuffer
- Inherits:
-
Object
- Object
- Lightstreamer::LineBuffer
- Defined in:
- lib/lightstreamer/line_buffer.rb
Overview
Helper class that takes an incoming stream of ASCII data and yields back individual lines as they become complete.
Instance Method Summary collapse
-
#initialize ⇒ LineBuffer
constructor
A new instance of LineBuffer.
-
#process(data) ⇒ Object
Appends a new piece of ASCII data to this buffer.
Constructor Details
#initialize ⇒ LineBuffer
Returns a new instance of LineBuffer.
4 5 6 |
# File 'lib/lightstreamer/line_buffer.rb', line 4 def initialize @buffer = '' end |
Instance Method Details
#process(data) ⇒ Object
Appends a new piece of ASCII data to this buffer. Any lines that are now complete will be yielded back.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lightstreamer/line_buffer.rb', line 11 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 |