class TestBench::Output::Timer
Constants
- Error
Attributes
start_time[RW]
Public Class Methods
configure(receiver, attr_name: nil)
click to toggle source
# File lib/test_bench/output/timer.rb, line 8 def self.configure(receiver, attr_name: nil) attr_name ||= :timer instance = new receiver.public_send(:"#{attr_name}=", instance) instance end
Public Instance Methods
mode()
click to toggle source
# File lib/test_bench/output/timer.rb, line 48 def mode if start_time.nil? Mode.stopped else Mode.running end end
reset()
click to toggle source
# File lib/test_bench/output/timer.rb, line 56 def reset previous_start_time = self.start_time self.start_time = nil previous_start_time end
running?()
click to toggle source
# File lib/test_bench/output/timer.rb, line 40 def running? mode == Mode.running end
start(now=nil)
click to toggle source
# File lib/test_bench/output/timer.rb, line 16 def start(now=nil) now ||= ::Time.now.utc if mode == Mode.running raise Error, "Timer has already started (Start Time: #{start_time})" end self.start_time = now end
stop(now=nil)
click to toggle source
# File lib/test_bench/output/timer.rb, line 26 def stop(now=nil) now ||= ::Time.now.utc if mode == Mode.stopped raise Error, "Timer has not started" end start_time = reset elapsed = now - start_time elapsed.round(3) end
stopped?()
click to toggle source
# File lib/test_bench/output/timer.rb, line 44 def stopped? mode == Mode.stopped end