Class | Irc::Bot::MessageParameter |
In: |
lib/rbot/messagemapper.rb
|
Parent: | Object |
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.
default | [RW] | |
multi | [W] | |
name | [R] | |
optional | [W] |
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.
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.