]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/utils/extends.rb
+ (extends) :limit option support in ircify_html()
[user/henk/code/ruby/rbot.git] / lib / rbot / core / utils / extends.rb
index 1aa6d457a00e4f48fa7ad464128921cf6c0bfe32..80bad3836b8725b0b6fac45c8f57e4bc49389435 100644 (file)
@@ -85,8 +85,7 @@ end
 
 # Extensions to the String class
 #
-# TODO make ircify_html() accept an Hash of options, and make riphtml() just
-# call ircify_html() with stronger purify options.
+# TODO make riphtml() just call ircify_html() with stronger purify options.
 #
 class ::String
 
@@ -156,9 +155,14 @@ class ::String
 
     # And finally whitespace is squeezed
     txt.gsub!(/\s+/, ' ')
+    txt.strip!
+
+    if opts[:limit] && txt.size > opts[:limit]
+      txt = txt.slice(0, opts[:limit]) + "#{Reverse}...#{Reverse}"
+    end
 
     # Decode entities and strip whitespace
-    return txt.strip
+    return txt
   end
 
   # As above, but modify the receiver