Class: PacketIO::LineBasedProtocol

Inherits:
Base
  • Object
show all
Defined in:
lib/packet_io/io_listener.rb

Instance Method Summary collapse

Methods inherited from Base

#<<, #initialize, #on_data

Constructor Details

This class inherits a constructor from PacketIO::Base

Instance Method Details

#receive(data) ⇒ Object

strip newlines from received data and pass on complete lines

Parameters:

  • data (String)


86
87
88
89
90
91
92
93
# File 'lib/packet_io/io_listener.rb', line 86

def receive(data)
  @data ||= StringScanner.new("")
  @data = @data.concat(data)
  while s = @data.scan(/.*?\n/)
    forward(s.strip)
  end
  nil
end

#write(data) ⇒ Object

add a newline to data and pass it on

Parameters:

  • data (String)


98
99
100
# File 'lib/packet_io/io_listener.rb', line 98

def write(data)
  super(data + "\n")
end