module Potato module IRC # A line from an IRC client. class Packet # The first word of the packet, usually all-caps. # @return [String] attr_reader :cmd # Any words in the packet that aren't part of the content. # @return [Array] attr_reader :args # Content of the packet (after a colon). # @return [String, nil] attr_reader :content # The actual packet string. # @return [String] attr_reader :raw def initialize str str = str.force_encoding("UTF-8") if str.respond_to?(:force_encoding) @raw = str if str.include?(" :") @cmd, *@args, @content = str.split(" ", str[0...str.index(" :")+1].count(" ") + 1) @content.slice!(0) else @cmd, *@args = str.split(" ") end @cmd.upcase! @content = @args.pop(@args.size - 1).join(" ") if @cmd == "PRIVMSG" && @content.nil? end # The first argument whose first character is an octothorpe (#), or nil if none is found. # @return [String] def room @args.find{|a|a =~ /^#/}[1..-1] end end end end