summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/irc.rb30
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