Class: Lightstreamer::StreamBuffer

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeStreamBuffer

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.

Parameters:

  • data (String)

    The new piece of ASCII data.

Yield Parameters:

  • line (String)

    The new line that is 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