Class: Stoppur::Stopwatch

Inherits:
Object
  • Object
show all
Defined in:
lib/stoppur/stopwatch.rb

Constant Summary collapse

AlreadyStartedError =
Class.new(StandardError)
NotStartedError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(clock) ⇒ Stopwatch

Returns a new instance of Stopwatch.



5
6
7
# File 'lib/stoppur/stopwatch.rb', line 5

def initialize(clock)
  @clock = clock
end

Instance Method Details

#elapsedObject

Raises:



15
16
17
18
# File 'lib/stoppur/stopwatch.rb', line 15

def elapsed
  raise NotStartedError unless started?
  @clock.time - @start_time
end

#startObject



9
10
11
12
13
# File 'lib/stoppur/stopwatch.rb', line 9

def start
  raise AlreadyStartedError if started?
  @start_time = @clock.time
  self
end