class ShellTest::ShellMethods::Timer
Attributes
clock[R]
start_time[R]
step_time[R]
stop_time[R]
Public Class Methods
new(clock=Time)
click to toggle source
# File lib/shell_test/shell_methods/timer.rb 9 def initialize(clock=Time) 10 @clock = clock 11 reset 12 end
Public Instance Methods
current_time()
click to toggle source
# File lib/shell_test/shell_methods/timer.rb 14 def current_time 15 clock.now.to_f 16 end
elapsed_time()
click to toggle source
# File lib/shell_test/shell_methods/timer.rb 35 def elapsed_time 36 current_time - start_time 37 end
reset()
click to toggle source
# File lib/shell_test/shell_methods/timer.rb 18 def reset 19 @start_time = nil 20 @stop_time = nil 21 @step_time = 0 22 end
running?()
click to toggle source
# File lib/shell_test/shell_methods/timer.rb 31 def running? 32 start_time.nil? || stop_time.nil? ? false : true 33 end
start(max_run_time=60)
click to toggle source
# File lib/shell_test/shell_methods/timer.rb 24 def start(max_run_time=60) 25 reset 26 @start_time = current_time 27 @stop_time = start_time + max_run_time 28 @step_time = stop_time 29 end
stop()
click to toggle source
# File lib/shell_test/shell_methods/timer.rb 39 def stop 40 if running? 41 elapsed = elapsed_time 42 reset 43 elapsed 44 else 45 nil 46 end 47 end
timeout()
click to toggle source
# File lib/shell_test/shell_methods/timer.rb 65 def timeout 66 timeout = step_time - current_time 67 timeout < 0 ? 0 : timeout 68 end
timeout=(timeout)
click to toggle source
# File lib/shell_test/shell_methods/timer.rb 49 def timeout=(timeout) 50 unless running? 51 raise "cannot set timeout unless running" 52 end 53 54 case 55 when timeout.nil? 56 @step_time = stop_time 57 when timeout < 0 58 step_time 59 else 60 mtime = current_time + timeout 61 @step_time = mtime > stop_time ? stop_time : mtime 62 end 63 end