class Lightstreamer::StreamBuffer

Helper class used by {StreamConnection} that takes an incoming stream of ASCII data and yields back individual lines as they become complete.

@private

Public Class Methods

new() click to toggle source
# File lib/lightstreamer/stream_buffer.rb, line 7
def initialize
  @buffer = ''
end

Public Instance Methods

process(data) { |strip| ... } click to toggle source

Appends a new piece of ASCII data to this buffer and yields back any lines that are now complete.

@param [String] data The new piece of ASCII data.

@yieldparam [String] line The new line that is now complete.

# 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