]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/utils/extends.rb
HTML processing refactoring: ensure HTML title works with and without Hpricot
[user/henk/code/ruby/rbot.git] / lib / rbot / core / utils / extends.rb
index 80bad3836b8725b0b6fac45c8f57e4bc49389435..dcc257a2df85330f073377ca95e38f21bf64250c 100644 (file)
@@ -123,7 +123,7 @@ class ::String
         str + ": " + link
       }
     else
-      warn "unknown :a_href option #{val} passed to ircify_html" if val
+      warning "unknown :a_href option #{val} passed to ircify_html" if val
     end
 
     # Paragraph and br tags are converted to whitespace
@@ -178,6 +178,23 @@ class ::String
   def riphtml
     self.gsub(/<[^>]+>/, '').gsub(/&amp;/,'&').gsub(/&quot;/,'"').gsub(/&lt;/,'<').gsub(/&gt;/,'>').gsub(/&ellip;/,'...').gsub(/&apos;/, "'").gsub("\n",'')
   end
+
+  # This method tries to find an HTML title in the string,
+  # and returns it if found
+  def get_html_title
+    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
+    self.get_html_title.ircify_html rescue nil
+  end
 end