From 9407e52accbd3d4d97063a238f5e77dae39c273e Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 6 Feb 2007 09:46:52 +0000 Subject: New IRC Framework: more convenience methods to look into Netmask, User and Channel Lists --- lib/rbot/irc.rb | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3