]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/utils/utils.rb
utils: don't hang when getting first par with nonexistant uri-fragment
[user/henk/code/ruby/rbot.git] / lib / rbot / core / utils / utils.rb
index 529c37bd2ca5bbdd330de116e89926816739c3ce..ce5cdea4917cabafa55f88a5b8896accf1054898 100644 (file)
@@ -223,6 +223,22 @@ module ::Irc
       end
     end
 
+    # Turn a number of seconds into a hours:minutes:seconds e.g.
+    # 3:18:10 or 5'12" or 7s
+    #
+    def Utils.secs_to_short(seconds)
+      secs = seconds.to_i # make sure it's an integer
+      mins, secs = secs.divmod 60
+      hours, mins = mins.divmod 60
+      if hours > 0
+        return ("%s:%s:%s" % [hours, mins, secs])
+      elsif mins > 0
+        return ("%s'%s\"" % [mins, secs])
+      else
+        return ("%ss" % [secs])
+      end
+    end
+
 
     # Execute an external program, returning a String obtained by redirecting
     # the program's standards errors and output 
@@ -602,11 +618,18 @@ module ::Irc
     # uri_fragment:: the URI fragment of the original request
     #
     def Utils.get_string_html_info(text, opts={})
+      debug "getting string html info"
       txt = text.dup
       title = txt.ircify_html_title
+      debug opts
       if frag = opts[:uri_fragment] and not frag.empty?
-        fragreg = /.*?<a\s+[^>]*name=["']?#{frag}["']?.*?>/im
-        txt.sub!(fragreg,'')
+        fragreg = /<a\s+[^>]*name=["']?#{frag}["']?[^>]*>/im
+        debug fragreg
+        debug txt
+        if txt.match(fragreg)
+          # grab the post-match
+          txt = $'
+        end
       end
       c_opts = opts.dup
       c_opts[:strip] ||= title