Class: Stoppur::Stopwatch
- Inherits:
-
Object
- Object
- Stoppur::Stopwatch
- Defined in:
- lib/stoppur/stopwatch.rb
Constant Summary collapse
- AlreadyStartedError =
Class.new(StandardError)
- NotStartedError =
Class.new(StandardError)
Instance Method Summary collapse
- #elapsed ⇒ Object
-
#initialize(clock) ⇒ Stopwatch
constructor
A new instance of Stopwatch.
- #start ⇒ Object
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
#elapsed ⇒ Object
15 16 17 18 |
# File 'lib/stoppur/stopwatch.rb', line 15 def elapsed raise NotStartedError unless started? @clock.time - @start_time end |
#start ⇒ Object
9 10 11 12 13 |
# File 'lib/stoppur/stopwatch.rb', line 9 def start raise AlreadyStartedError if started? @start_time = @clock.time self end |