Class: SparklingWatir::Wait::Timer
- Inherits:
-
Object
- Object
- SparklingWatir::Wait::Timer
- Defined in:
- lib/sparkling_watir/wait/timer.rb
Overview
This class provides the time use on waits
Instance Method Summary collapse
-
#initialize(timeout: nil) ⇒ Timer
constructor
A new instance of Timer.
- #locked? ⇒ Boolean
- #remaining_time ⇒ Object
- #reset! ⇒ Object
-
#wait(timeout) { ... } ⇒ Object
private
Executes given block until it returns true or exceeds timeout.
Constructor Details
#initialize(timeout: nil) ⇒ Timer
Returns a new instance of Timer.
7 8 9 10 |
# File 'lib/sparkling_watir/wait/timer.rb', line 7 def initialize(timeout: nil) @end_time = timeout ? current_time + timeout : nil @remaining_time = @end_time - current_time if @end_time end |
Instance Method Details
#locked? ⇒ Boolean
36 37 38 |
# File 'lib/sparkling_watir/wait/timer.rb', line 36 def locked? !@end_time.nil? end |
#remaining_time ⇒ Object
28 29 30 |
# File 'lib/sparkling_watir/wait/timer.rb', line 28 def remaining_time @end_time - current_time end |
#reset! ⇒ Object
32 33 34 |
# File 'lib/sparkling_watir/wait/timer.rb', line 32 def reset! @end_time = nil end |
#wait(timeout) { ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Executes given block until it returns true or exceeds timeout.
19 20 21 22 23 24 25 26 |
# File 'lib/sparkling_watir/wait/timer.rb', line 19 def wait(timeout, &block) end_time = @end_time || current_time + timeout loop do yield(block) @remaining_time = end_time - current_time break if @remaining_time.negative? end end |