diff options
author | Dmitry Kim <dmitry point kim at gmail point com> | 2007-09-22 13:31:20 +0000 |
---|---|---|
committer | Dmitry Kim <dmitry point kim at gmail point com> | 2007-09-22 13:31:20 +0000 |
commit | 0aa0919fdbfa148dfbb5961f14f27e41085959b4 (patch) | |
tree | 3bcd4d503185e802fcdc1866ac600b8765ce1350 | |
parent | 290656ebffce720540f5a767066d914840e583c8 (diff) |
+ (irc) generalize() method for Netmask class
-rw-r--r-- | lib/rbot/irc.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index 371762cb..2a4642a2 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -751,6 +751,26 @@ module Irc return @nick.has_irc_glob? || @user.has_irc_glob? || @host.has_irc_glob?
end
+ def generalize
+ u = user.dup
+ unless u.has_irc_glob?
+ u.sub!(/^[in]=/, '=') or u.sub!(/^\W(\w+)/, '\1')
+ u = '*' + u
+ end
+
+ h = host.dup
+ unless h.has_irc_glob?
+ if h.include? '/'
+ h.sub!(/x-\w+$/, 'x-*')
+ else
+ h.match(/^[^\.]+\.[^\.]+$/) or
+ h.sub!(/^(\d+\.\d+\.\d+\.)\d+$/, '\1*') or
+ h.sub!(/^[^\.]+\./, '*.')
+ end
+ end
+ return Netmask.new("*!#{u}@#{h}", server_and_casemap)
+ end
+
# This method is used to match the current Netmask against another one
#
# The method returns true if each component of the receiver matches the
|