class IRCParser::RFCWireFormat::MessageTokenizer
Internal: Tokenizer for the RFC wire format.
Public Class Methods
new(message)
click to toggle source
# File lib/ircparser/wire/rfc.rb, line 24 def initialize message @message = message # Skip any preceding whitespace. This is technically invalid but # is implemented by several servers in the wild. @position = message.index(/\S/) || 0 end
Public Instance Methods
read_middle()
click to toggle source
Internal: Retrieves a space delimited token from the message.
# File lib/ircparser/wire/rfc.rb, line 32 def read_middle return nil if @position >= @message.length old_position = @position @position = @message.index(' ', old_position) || @message.length return nil unless (@position - old_position).positive? token = @message.slice old_position...@position @position = @message.index(/\S+/, @position) || @message.length return token end
read_trailing()
click to toggle source
Internal: Retrieves a space delimited token that may be a <trailing> parameter.
message - The message to retrieve the token from.
# File lib/ircparser/wire/rfc.rb, line 45 def read_trailing return nil if @position >= @message.length if @message[@position] == ':' token = @message[@position+1..-1] @position = @message.length return token end return read_middle end