class DDMetrics::Stopwatch

Public Class Methods

new() click to toggle source
# File lib/ddmetrics/stopwatch.rb, line 23
def initialize
  @duration = 0.0
  @last_start = nil
end

Public Instance Methods

duration() click to toggle source
# File lib/ddmetrics/stopwatch.rb, line 39
def duration
  raise StillRunningError if running?
  @duration
end
running?() click to toggle source
# File lib/ddmetrics/stopwatch.rb, line 44
def running?
  !@last_start.nil?
end
start() click to toggle source
# File lib/ddmetrics/stopwatch.rb, line 28
def start
  raise AlreadyRunningError if running?
  @last_start = Time.now
end
stop() click to toggle source
# File lib/ddmetrics/stopwatch.rb, line 33
def stop
  raise NotRunningError unless running?
  @duration += (Time.now - @last_start)
  @last_start = nil
end
stopped?() click to toggle source
# File lib/ddmetrics/stopwatch.rb, line 48
def stopped?
  !running?
end