Class: PacketIO::LineBasedProtocol
- Defined in:
- lib/packet_io/io_listener.rb
Instance Method Summary collapse
-
#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
This class inherits a constructor from PacketIO::Base
Instance Method Details
#receive(data) ⇒ Object
strip newlines from received data and pass on complete lines
86 87 88 89 90 91 92 93 94 |
# File 'lib/packet_io/io_listener.rb', line 86 def receive(data) @memo ||= "" scanner = StringScanner.new(@memo + data) while s = scanner.scan(/.*?\n/) forward(s.strip) end @memo = scanner.rest nil end |
#write(data) ⇒ Object
add a newline to data and pass it on
99 100 101 |
# File 'lib/packet_io/io_listener.rb', line 99 def write(data) super(data + "\n") end |