]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
+ (irc) generalize() method for Netmask class
authorDmitry Kim <dmitry point kim at gmail point com>
Sat, 22 Sep 2007 13:31:20 +0000 (13:31 +0000)
committerDmitry Kim <dmitry point kim at gmail point com>
Sat, 22 Sep 2007 13:31:20 +0000 (13:31 +0000)
lib/rbot/irc.rb

index 371762cb118f6d692c9584a38a553eb5ba0e031c..2a4642a2e1607e02781d7927208d0be05d7e7705 100644 (file)
@@ -751,6 +751,26 @@ module Irc
       return @nick.has_irc_glob? || @user.has_irc_glob? || @host.has_irc_glob?\r
     end\r
 \r
+    def generalize\r
+      u = user.dup\r
+      unless u.has_irc_glob?\r
+        u.sub!(/^[in]=/, '=') or u.sub!(/^\W(\w+)/, '\1')\r
+        u = '*' + u\r
+      end\r
+\r
+      h = host.dup\r
+      unless h.has_irc_glob?\r
+        if h.include? '/'\r
+          h.sub!(/x-\w+$/, 'x-*')\r
+        else\r
+          h.match(/^[^\.]+\.[^\.]+$/) or\r
+          h.sub!(/^(\d+\.\d+\.\d+\.)\d+$/, '\1*') or\r
+          h.sub!(/^[^\.]+\./, '*.')\r
+        end\r
+      end\r
+      return Netmask.new("*!#{u}@#{h}", server_and_casemap)\r
+    end\r
+\r
     # This method is used to match the current Netmask against another one\r
     #\r
     # The method returns true if each component of the receiver matches the\r