lib/ircsupport/parser.rb in ircsupport-0.1.0 vs lib/ircsupport/parser.rb in ircsupport-0.2.0

- old
+ new

@@ -52,20 +52,20 @@ "B" => ["k"], "C" => ["l"], "D" => %w[i m n p s t r] }, "MODES" => 1, - "NICKLEN" => 999, - "MAXBANS" => 999, - "TOPICLEN" => 999, - "KICKLEN" => 999, - "CHANNELLEN" => 999, + "NICKLEN" => Float::INFINITY, + "MAXBANS" => Float::INFINITY, + "TOPICLEN" => Float::INFINITY, + "KICKLEN" => Float::INFINITY, + "CHANNELLEN" => Float::INFINITY, "CHIDLEN" => 5, - "AWAYLEN" => 999, + "AWAYLEN" => Float::INFINITY, "MAXTARGETS" => 1, - "MAXCHANNELS" => 999, - "CHANLIMIT" => {"#" => 999}, + "MAXCHANNELS" => Float::INFINITY, + "CHANLIMIT" => {"#" => Float::INFINITY}, "STATUSMSG" => ["@", "+"], "CASEMAPPING" => :rfc1459, "ELIST" => [], "MONITOR" => 0, } @@ -79,16 +79,17 @@ # A list of currently enabled capabilities. # It will be updated in response to parsed {IRCSupport::Message::CAP::ACK `CAP ACK`} messages. # @return [Array] attr_reader :capabilities - # @return [IRCSupport::Parser] + # @private def initialize @isupport = @@default_isupport @capabilities = [] end + # Perform low-level parsing of an IRC protocol line. # @param [String] line An IRC protocol line you wish to decompose. # @return [Hash] A decomposed IRC protocol line with 3 keys: # `command`, the IRC command; `prefix`, the prefix to the # command, if any; `args`, an array of any arguments to the command def decompose_line(line) @@ -105,10 +106,11 @@ end return elems end + # Compose an IRC protocol line. # @param [Hash] elems The attributes of the message (as returned # by {#decompose_line}). # @return [String] An IRC protocol line. def compose_line(elems) line = '' @@ -132,10 +134,11 @@ end return line end + # Parse an IRC protocol line into a complete message object. # @param [String] line An IRC protocol line. # @return [IRCSupport::Message] A parsed message object. def parse(line) elems = decompose_line(line) elems[:isupport] = @isupport @@ -188,13 +191,13 @@ msg_const = constantize("IRCSupport::Message") end message = msg_const.new(elems) - if message.type == '005' + if message.type == :'005' @isupport.merge! message.isupport - elsif message.type == 'cap_ack' + elsif message.type == :cap_ack message.capabilities.each do |capability, options| if options.include?(:disable) @capabilities = @capabilities - [capability] elsif options.include?(:enable) @capabilities = @capabilities + [capability] @@ -203,9 +206,10 @@ end return message end + # CTCP-quote a message. # @param [String] type The CTCP type. # @param [String] message The text of the CTCP message. # @return [String] A CTCP-quoted message. def ctcp_quote(type, message) line = low_quote(message)