Class: Rufus::Waiter
- Inherits:
-
Object
- Object
- Rufus::Waiter
- Defined in:
- lib/rufus/waiter.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
5
- DEFAULT_INTERVAL =
0.2
Instance Method Summary collapse
-
#initialize(selenium, opts = {}) ⇒ Waiter
constructor
A new instance of Waiter.
- #until(&block) ⇒ Object
Constructor Details
#initialize(selenium, opts = {}) ⇒ Waiter
Returns a new instance of Waiter.
8 9 10 11 12 |
# File 'lib/rufus/waiter.rb', line 8 def initialize(selenium, opts={}) @selenium = selenium @timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT) @interval = opts.fetch(:interval, DEFAULT_INTERVAL) end |
Instance Method Details
#until(&block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rufus/waiter.rb', line 14 def until(&block) time = Time.now + @timeout while Time.now < time @selenium.reset_page_source value = block.call if block return value if value sleep @interval end false end |