X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Futils.rb;h=a1a8c4843670872516755c1d7fd6278458eadd11;hb=f841a9060041bdb57dbfa3169212ba57936619c9;hp=4c474ae4f246291c596c92533d18597a948e3445;hpb=676dd61e6b0bea5f506d064039a685944aefd6fb;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/utils.rb b/lib/rbot/utils.rb index 4c474ae4..a1a8c484 100644 --- a/lib/rbot/utils.rb +++ b/lib/rbot/utils.rb @@ -6,6 +6,24 @@ module Irc # miscellaneous useful functions module Utils + # turn a number of seconds into a human readable string, e.g + # 2 days, 3 hours, 18 minutes, 10 seconds + def Utils.secs_to_string(secs) + ret = "" + days = (secs / (60 * 60 * 24)).to_i + secs = secs % (60 * 60 * 24) + hours = (secs / (60 * 60)).to_i + secs = (secs % (60 * 60)) + mins = (secs / 60).to_i + secs = (secs % 60).to_i + ret += "#{days} days, " if days > 0 + ret += "#{hours} hours, " if hours > 0 || days > 0 + ret += "#{mins} minutes and " if mins > 0 || hours > 0 || days > 0 + ret += "#{secs} seconds" + return ret + end + + def Utils.safe_exec(command, *args) IO.popen("-") {|p| if(p)