]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
HTML processing refactoring: ensure HTML title works with and without Hpricot
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 18 Sep 2007 06:15:47 +0000 (06:15 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 18 Sep 2007 06:15:47 +0000 (06:15 +0000)
lib/rbot/core/utils/extends.rb

index 0b07257a1b58a42b2fe4d98b6da40ba43beb63f7..dcc257a2df85330f073377ca95e38f21bf64250c 100644 (file)
@@ -182,15 +182,18 @@ class ::String
   # This method tries to find an HTML title in the string,
   # and returns it if found
   def get_html_title
-    return unless Irc::Utils::TITLE_REGEX.match(self)
-    $1
+    if defined? ::Hpricot
+      Hpricot(self).at("title").inner_html
+    else
+      return unless Irc::Utils::TITLE_REGEX.match(self)
+      $1
+    end
   end
 
   # This method returns the IRC-formatted version of an
   # HTML title found in the string
   def ircify_html_title
-    return unless Irc::Utils::TITLE_REGEX.match(self)
-    $1.ircify_html
+    self.get_html_title.ircify_html rescue nil
   end
 end