Class: Net::IRC::Message

### Home Classes Methods

### In Files

- lib/net/irc/message.rb

### Parent

Object

### Namespace

- CLASS Net::IRC::Message::InvalidMessage
- CLASS Net::IRC::Message::ModeParser
- CLASS Net::IRC::Message::ServerConfig

### Methods

- ::new
- ::parse
- #[]
- #ctcp?
- #ctcps
- #each
- #inspect
- #to_a
- #to_s
- #to_str

### Included Modules

- Net::IRC

### Files

- README

### Class/Module Index

Quicksearch

- Net
- Net::IRC
- Net::IRC::Client
- Net::IRC::Client::ChannelManager
- Net::IRC::IRCException
- Net::IRC::Message
- Net::IRC::Message::InvalidMessage
- Net::IRC::Message::ModeParser
- Net::IRC::Message::ServerConfig
- Net::IRC::Prefix
- Net::IRC::Server
- Net::IRC::Server::Session
- Object

No matching classes.

# Net::IRC::Message

### Public Class Methods

new(prefix, command, params) click to toggle source

    # File lib/net/irc/message.rb, line 35
    def initialize(prefix, command, params)
            @prefix  = Prefix.new(prefix.to_s)
            @command = command
            @params  = params
    end

parse(str) click to toggle source

Parse string and return new Message. If the string is invalid message, this method raises Net::IRC::Message::InvalidMessage.

    # File lib/net/irc/message.rb, line 10
    def self.parse(str)
            _, prefix, command, *rest = *PATTERN::MESSAGE_PATTERN.match(str)
            raise InvalidMessage, "Invalid message: #{str.dump}" unless _

            case
            when rest[0] && !rest[0].empty?
                    middle, trailer, = *rest
            when rest[2] && !rest[2].empty?
                    middle, trailer, = *rest[2, 2]
            when rest[1]
                    params  = []
                    trailer = rest[1]
            when rest[3]
                    params  = []
                    trailer = rest[3]
            else
                    params  = []
            end

            params ||= middle.split(/ /)[1..-1]
            params << trailer if trailer

            new(prefix, command, params)
    end

### Public Instance Methods

[](n) click to toggle source

Same as @params.

    # File lib/net/irc/message.rb, line 42
    def [](n)
            @params[n]
    end

ctcp?() click to toggle source

If the message is CTCP, return true.

    # File lib/net/irc/message.rb, line 80
    def ctcp?
            #message = @params[1]
            #message[0] == ?\01 && message[-1] == ?\01
            /\x01(?>[^\x00\x01\r\n]*)\x01/ === @params[1]
    end

ctcps() click to toggle source

    # File lib/net/irc/message.rb, line 86
    def ctcps
            messages = []
            @params[1].gsub!(/\x01(?>[^\x00\x01\r\n]*)\x01/) do
                    messages << ctcp_decode($&)
                    ""
            end
            messages
    end

each(&block) click to toggle source

Iterate params.

    # File lib/net/irc/message.rb, line 47
    def each(&block)
            @params.each(&block)
    end

inspect() click to toggle source

    # File lib/net/irc/message.rb, line 95
    def inspect
            "#<%s:0x%x prefix:%s command:%s params:%s>" % [
                    self.class,
                    self.object_id,
                    @prefix,
                    @command,
                    @params.inspect
            ]
    end

to_a() click to toggle source

Same as params.

    # File lib/net/irc/message.rb, line 75
    def to_a
            @params.dup
    end

to_s() click to toggle source

Stringfy message to raw IRC message.

    # File lib/net/irc/message.rb, line 52
    def to_s
            str = ""

            str << ":#{@prefix} " unless @prefix.empty?
            str << @command

            if @params
                    f = false
                    @params.each do |param|
                            f = !f && (param.empty? || param[0] == :: || param.include?(" "))
                            str << " "
                            str << ":" if f
                            str << param
                    end
            end

            str << "\x0D\x0A"

            str
    end

Also aliased as: to_str
to_str() click to toggle source
Alias for: to_s

[Validate]

Generated with the Darkfish Rdoc Generator 2.