### Home Classes Methods

### In Files

- lib/rbot/messagemapper.rb

### Parent

Object

### Methods

- ::new
- #collect
- #collector=
- #inspect
- #multi?
- #name=
- #optional?

### Class/Module Index

Quicksearch

- Irc
- Irc::AsciiCasemap
- Irc::BanlistMessage
- Irc::BasicUserMessage
- Irc::Bot
- Irc::Bot::Auth
- Irc::Bot::Auth::BotOwnerClass
- Irc::Bot::Auth::BotUser
- Irc::Bot::Auth::Command
- Irc::Bot::Auth::DefaultBotUserClass
- Irc::Bot::Auth::InvalidPassword
- Irc::Bot::Auth::ManagerClass
- Irc::Bot::Auth::PermissionSet
- Irc::Bot::Config
- Irc::Bot::Config::ArrayValue
- Irc::Bot::Config::BooleanValue
- Irc::Bot::Config::EnumValue
- Irc::Bot::Config::FloatValue
- Irc::Bot::Config::IntegerValue
- Irc::Bot::Config::ManagerClass
- Irc::Bot::Config::StringValue
- Irc::Bot::Config::Value
- Irc::Bot::Config::Wizard
- Irc::Bot::DataFilter
- Irc::Bot::DataStream
- Irc::Bot::Language
- Irc::Bot::MessageMapper
- Irc::Bot::MessageMapper::Failure
- Irc::Bot::MessageMapper::FriendlyFailure
- Irc::Bot::MessageMapper::NoActionFailure
- Irc::Bot::MessageMapper::NoMatchFailure
- Irc::Bot::MessageMapper::NotPrivateFailure
- Irc::Bot::MessageMapper::NotPublicFailure
- Irc::Bot::MessageMapper::PartialMatchFailure
- Irc::Bot::MessageParameter
- Irc::Bot::MessageTemplate
- Irc::Bot::Plugins
- Irc::Bot::Plugins::BotModule
- Irc::Bot::Plugins::CoreBotModule
- Irc::Bot::Plugins::Plugin
- Irc::Bot::Plugins::PluginManagerClass
- Irc::Bot::Plugins::RecurseTooDeep
- Irc::Bot::Plugins::RemoteBotModule
- Irc::Bot::Plugins::RemoteCoreBotModule
- Irc::Bot::Plugins::RemotePlugin
- Irc::Bot::Registry
- Irc::Bot::Registry::Accessor
- Irc::Bot::RemoteDispatcher
- Irc::Bot::RemoteMessage
- Irc::Bot::RemoteObject
- Irc::Bot::Wordlist
- Irc::BotConfig
- Irc::Casemap
- Irc::Channel
- Irc::Channel::Mode
- Irc::Channel::ModeHash
- Irc::Channel::ModeTypeA
- Irc::Channel::ModeTypeB
- Irc::Channel::ModeTypeC
- Irc::Channel::ModeTypeD
- Irc::Channel::Topic
- Irc::Channel::UserMode
- Irc::ChannelList
- Irc::Client
- Irc::DBHash
- Irc::DBTree
- Irc::InviteMessage
- Irc::JoinMessage
- Irc::KickMessage
- Irc::MessageQueue
- Irc::ModeChangeMessage
- Irc::MotdMessage
- Irc::NamesMessage
- Irc::Netmask
- Irc::NetmaskDb
- Irc::NetmaskDb::Tree
- Irc::NetmaskList
- Irc::NickMessage
- Irc::NoSuchTargetMessage
- Irc::NoticeMessage
- Irc::PartMessage
- Irc::PrivMessage
- Irc::QueueRing
- Irc::QuitMessage
- Irc::RfcCasemap
- Irc::Server
- Irc::ServerOrCasemap
- Irc::Socket
- Irc::Socket::IdentityFilter
- Irc::StrictRfcCasemap
- Irc::TopicMessage
- Irc::UnknownMessage
- Irc::User
- Irc::UserList
- Irc::UserMessage
- Irc::Utils
- Irc::Utils::HttpUtil
- Irc::Utils::HttpUtil::CachedObject
- Irc::Utils::ParseTime
- Irc::WelcomeMessage
- Irc::WhoisMessage
- BDB
- BDB::CIBtree
- MonitorMixin
- MonitorMixin::ConditionVariable
- Net
- Net::HTTPResponse
- Regexp
- Regexp::Irc
- Singleton
- Singleton::SingletonClassMethods
- Timer
- Timer::Action
- TokyoCabinet
- TokyoCabinet::CIBDB
- UnicodePlugin
- UnicodePlugin::UnicodeFilter
- Array
- ArrayOf
- AuthModule
- BasicsModule
- ConditionVariable
- ConfigModule
- DottedIndex
- Enumerable
- Exception
- FiltersModule
- GetText
- GetTextVersionError
- HttpUtilPlugin
- IrcLogModule
- Module
- Numeric
- Object
- Range
- RemoteModule
- ServerError
- String
- Symbol
- UserDataModule
- WordlistModule
- YAML

No matching classes.

# Irc::Bot::MessageParameter

MessageParameter is a class that collects all the necessary information about a message (dynamic) parameter (the :param or *param that can be found in a map).

It has a `name` attribute, `multi` and `optional` booleans that tell if the parameter collects more than one word, and if it's optional (respectively). In the latter case, it can also have a default value.

It is possible to assign a collector to a MessageParameter. This can be either a Regexp with captures or an Array or a Hash. The collector defines what the collect() method is supposed to return.

### Attributes

default[RW]
multi[W]
name[R]
optional[W]

### Public Class Methods

new(name) click to toggle source

    # File lib/rbot/messagemapper.rb, line 314
    def initialize(name)
      self.name = name
      @multi = false
      @optional = false
      @default = nil
      @regexp = nil
      @index = nil
    end

### Public Instance Methods

collect(val) click to toggle source

This method is used to turn a matched item into the actual parameter value. It only does something when collector= set the @regexp to something. In this case, val is matched against @regexp and then the match result specified in @index is selected. As a special case, when @index is nil the first non-nil captured group is returned.

    # File lib/rbot/messagemapper.rb, line 340
    def collect(val)
      return val unless @regexp
      mdata = @regexp.match(val)
      if @index
        return mdata[@index]
      else
        return mdata[1..-1].compact.first
      end
    end

collector=(val) click to toggle source

This method allow the plugin programmer to choose to only pick a subset of the string matched by a parameter. This is done by passing the collector=() method either a Regexp with captures or an Array or a Hash.

When the method is passed a Regexp with captures, the collect() method will return the first non-nil captured group.

When the method is passed an Array, it will grab a regexp from the first element, and possibly an index from the second element. The index can also be nil.

When the method is passed a Hash, it will grab a regexp from the :regexp element, and possibly an index from the :index element. The index can also be nil.

    # File lib/rbot/messagemapper.rb, line 364
    def collector=(val)
      return unless val
      case val
      when Regexp
        return unless val.has_captures?
        @regexp = val
      when Array
        warning "Collector #{val.inspect} is too long, ignoring extra entries" unless val.length <= 2
        @regexp = val[0]
        @index = val[1] rescue nil
      when Hash
        raise "Collector #{val.inspect} doesn't have a :regexp key" unless val.has_key?(:regexp)
        @regexp = val[:regexp]
        @index = val.fetch(:regexp, nil)
      end
      raise "The regexp of collector #{val.inspect} isn't a Regexp" unless @regexp.kind_of?(Regexp)
      raise "The index of collector #{val.inspect} is present but not an integer " if @index and not @index.kind_of?(Fixnum)
    end

inspect() click to toggle source

    # File lib/rbot/messagemapper.rb, line 383
    def inspect
      mul = multi? ? " multi" : " single"
      opt = optional? ? " optional" : " needed"
      if @regexp
        reg = " regexp=%s index=%s" % [@regexp, @index]
      else
        reg = nil
      end
      "<%s %s%s%s%s>" % [self.class, name, mul, opt, reg]
    end

multi?() click to toggle source

    # File lib/rbot/messagemapper.rb, line 327
    def multi?
      @multi
    end

name=(val) click to toggle source

    # File lib/rbot/messagemapper.rb, line 323
    def name=(val)
      @name = val.to_sym
    end

optional?() click to toggle source

    # File lib/rbot/messagemapper.rb, line 331
    def optional?
      @optional
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.