Class: PacketIO::LineBasedProtocol
- Defined in:
- lib/packet_io/io_listener.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ LineBasedProtocol
constructor
A new instance of LineBasedProtocol.
-
#receive(data) ⇒ Object
strip newlines from received data and pass on complete lines.
-
#write(data) ⇒ Object
add a newline to data and pass it on.
Methods inherited from Base
Constructor Details
#initialize(*args) ⇒ LineBasedProtocol
Returns a new instance of LineBasedProtocol.
81 82 83 84 |
# File 'lib/packet_io/io_listener.rb', line 81 def initialize(*args) super @buffer = StringScanner.new("") end |
Instance Method Details
#receive(data) ⇒ Object
strip newlines from received data and pass on complete lines
90 91 92 93 94 95 96 |
# File 'lib/packet_io/io_listener.rb', line 90 def receive(data) @buffer.concat(data) while s = @buffer.scan(/.*?\n/) forward(s.strip) end nil end |
#write(data) ⇒ Object
add a newline to data and pass it on
101 102 103 |
# File 'lib/packet_io/io_listener.rb', line 101 def write(data) super(data + "\n") end |