diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-02-06 09:46:52 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-02-06 09:46:52 +0000 |
commit | 9407e52accbd3d4d97063a238f5e77dae39c273e (patch) | |
tree | d6872e3765fab11bd1ba1f881f3f0ff11352189c | |
parent | 100f55b10d33f54cdddea52a3b256ca48a15d1d1 (diff) |
New IRC Framework: more convenience methods to look into Netmask, User and Channel Lists
-rw-r--r-- | lib/rbot/irc.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index f3964d83..ab730278 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -461,6 +461,13 @@ class ArrayOf < Array }
end
+ # We introduce the 'downcase' method, which maps downcase() to all the Array
+ # elements, properly failing when the elements don't have a downcase method
+ #
+ def downcase
+ self.map { |el| el.downcase }
+ end
+
# Modifying methods which we don't handle yet are made private
#
private :[]=, :collect!, :map!, :fill, :flatten!
@@ -684,7 +691,10 @@ module Irc end
# We enhance the [] method by allowing it to pick an element that matches
- # a given Netmask or String
+ # a given Netmask, a String or a Regexp
+ # TODO take into consideration the opportunity to use select() instead of
+ # find(), and/or a way to let the user choose which one to take (second
+ # argument?)
#
def [](*args)
if args.length == 1
@@ -697,6 +707,10 @@ module Irc self.find { |mask|
mask.matches?(args[0].to_irc_netmask(:casemap => mask.casemap))
}
+ when Regexp
+ self.find { |mask|
+ mask.fullform =~ args[0]
+ }
else
super(*args)
end
@@ -850,6 +864,13 @@ module Irc @element_class = User
end
+ # Convenience method: convert the UserList to a list of nicks. The indices
+ # are preserved
+ #
+ def nicks
+ self.map { |user| user.nick }
+ end
+
end
end
@@ -1206,6 +1227,13 @@ module Irc super(Channel, ar)
end
+ # Convenience method: convert the ChannelList to a list of channel names.
+ # The indices are preserved
+ #
+ def names
+ self.map { |chan| chan.name }
+ end
+
end
end
|