Class: Net::IRC::Message::ModeParser

### Home Classes Methods

### In Files

- lib/net/irc/message/modeparser.rb

### Parent

Object

### Methods

- ::new
- #mark_to_op
- #parse
- #set

### 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::ModeParser

### Constants

NO_PARAM
ONE_PARAM
ONE_PARAM_FOR_POSITIVE
ONE_PARAM_MASK

### Public Class Methods

new() click to toggle source

    # File lib/net/irc/message/modeparser.rb, line 8
    def initialize
            @modes          = {}
            @op_to_mark_map = {}
            @mark_to_op_map = {}

            # Initialize for ircd 2.11 (RFC2812+)
            set(:CHANMODES, 'beIR,k,l,imnpstaqr')
            set(:PREFIX, '(ov)@+')
    end

### Public Instance Methods

mark_to_op(mark) click to toggle source

    # File lib/net/irc/message/modeparser.rb, line 18
    def mark_to_op(mark)
            mark.empty? ? nil : @mark_to_op_map[mark.to_sym]
    end

parse(arg) click to toggle source

    # File lib/net/irc/message/modeparser.rb, line 43
    def parse(arg)
            params = arg.kind_of?(Net::IRC::Message) ? arg.to_a : arg.split(" ")
            params.shift

            ret = {
                    :positive => [],
                    :negative => [],
            }

            current = ret[:positive]
            until params.empty?
                    s = params.shift
                    s.scan(/./).each do |c|
                            c = c.to_sym
                            case c
                            when :+
                                    current = ret[:positive]
                            when :-
                                    current = ret[:negative]
                            else
                                    case @modes[c]
                                    when ONE_PARAM_MASK,ONE_PARAM
                                            current << [c, params.shift]
                                    when ONE_PARAM_FOR_POSITIVE
                                            if current.equal?(ret[:positive])
                                                    current << [c, params.shift]
                                            else
                                                    current << [c, nil]
                                            end
                                    when NO_PARAM
                                            current << [c, nil]
                                    else
                                            if @op_to_mark_map[c]
                                                    current << [c, params.shift]
                                            end
                                    end
                            end
                    end
            end

            ret
    end

set(key, value) click to toggle source

    # File lib/net/irc/message/modeparser.rb, line 22
    def set(key, value)
            case key
            when :PREFIX
                    if value =~ /\A\(([a-zA-Z]+)\)(.+)\z/
                            @op_to_mark_map = {}
                            key, value = Regexp.last_match[1], Regexp.last_match[2]
                            key.scan(/./).zip(value.scan(/./)) {|pair|
                                    @op_to_mark_map[pair[0].to_sym] = pair[1].to_sym
                            }
                            @mark_to_op_map = @op_to_mark_map.invert
                    end
            when :CHANMODES
                    @modes = {}
                    value.split(",").each_with_index do |s, kind|
                            s.scan(/./).each {|c|
                                    @modes[c.to_sym] = kind
                            }
                    end
            end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.