From 100f55b10d33f54cdddea52a3b256ca48a15d1d1 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 6 Feb 2007 00:11:38 +0000 Subject: New IRC Framework: NetmaskList now have an enhanced [] that allows retrieval by Netmask or String --- lib/rbot/irc.rb | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'lib/rbot') diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index e6262522..f3964d83 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -3,9 +3,11 @@ # * do we want to handle a Channel list for each User telling which # Channels is the User on (of those the client is on too)? # We may want this so that when a User leaves all Channels and he hasn't -# sent us privmsgs, we know remove him from the Server @users list +# sent us privmsgs, we know we can remove him from the Server @users list # * Maybe ChannelList and UserList should be HashesOf instead of ArrayOf? -# See items marked as TODO Ho +# See items marked as TODO Ho. +# The framework to do this is now in place, thanks to the new [] method +# for NetmaskList, which allows retrieval by Netmask or String #++ # :title: IRC module # @@ -681,6 +683,28 @@ module Irc super(Netmask, ar) end + # We enhance the [] method by allowing it to pick an element that matches + # a given Netmask or String + # + def [](*args) + if args.length == 1 + case args[0] + when Netmask + self.find { |mask| + mask.matches?(args[0]) + } + when String + self.find { |mask| + mask.matches?(args[0].to_irc_netmask(:casemap => mask.casemap)) + } + else + super(*args) + end + else + super(*args) + end + end + end end @@ -813,14 +837,17 @@ module Irc # A UserList is an ArrayOf Users + # We derive it from NetmaskList, which allows us to inherit any special + # NetmaskList method # - class UserList < ArrayOf + class UserList < NetmaskList # Create a new UserList, optionally filling it with the elements from # the Array argument fed to it. # def initialize(ar=[]) - super(User, ar) + super(ar) + @element_class = User end end -- cgit v1.2.3