| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Given a process that will take some amount of time, and we know how much we have done, and how much is still to do, what is the time remaining for the process to reach completion?
require 'time_remaining' time_remaining = McDowall::TimeRemaining.new tasks_done = 0.0 total_tasks = 20.0 tasks_remaining = total_tasks def do_task sleep (1 + rand(2)) end while( tasks_done < total_tasks ) do do_task( ) # Do whatever it is, transfer a byte, check a file etc. tasks_done+=1 tasks_remaining-=1 time_remaining.add ( (tasks_done/total_tasks).to_f ) p Time.now.to_s + " | " + time_remaining.completed_at.to_s # Prints "2011-06-22 22:45:38 -0400" p time_remaining # Prints "03:01:00" end
rspec spec
Copyright © 2011 John McDowall. See LICENSE for further details.
| Back | FazBrowse Home | New Git URL |