class IRCParser::Stream
Public: Parses IRC messages from a stream of data.
Attributes
block[R]
Public: The block which is called when a message is parsed.
buffer[R]
Public: The contents of the stream buffer.
Public Class Methods
new(&block)
click to toggle source
Public: Initialize a new stream.
# File lib/ircparser/stream.rb, line 28 def initialize &block unless block.is_a? Proc raise TypeError, "Wrong argument type #{block.class} (expected Proc)" end @block = block end
Public Instance Methods
append(data)
click to toggle source
Public: Appends data to the stream buffer.
data - The data to append.
# File lib/ircparser/stream.rb, line 38 def append data (@buffer ||= '') << data while @buffer.slice! /(.*?)\r?\n/ begin message = IRCParser::Message.parse $1 @block.call message, nil rescue IRCParser::Error => error @block.call nil, error end end end