Class: Timer
- Inherits:
-
Object
- Object
- Timer
- Defined in:
- lib/waitfor/timer.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Timer
constructor
A new instance of Timer.
- #out_of_time? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Timer
Returns a new instance of Timer.
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/waitfor/timer.rb', line 2 def initialize( ) @seconds = Timer.to_seconds if .instance_of? Hash @exception = [ :exception ] @exception = [ :error ] || @exception = [ :message ] end @exception ||= WaitFor::TimeoutError @start_time = Time.now end |
Class Method Details
.to_seconds(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/waitfor/timer.rb', line 15 def self.to_seconds( ) # Not a hash, already converted to seconds, return as is return if .instance_of? Fixnum seconds = [ :second ] || 0 seconds = [ :seconds ] || seconds minutes = [ :minute ] || 0 minutes = [ :minutes ] || minutes return seconds + minutes * 60 end |
Instance Method Details
#out_of_time? ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/waitfor/timer.rb', line 28 def out_of_time? if ( Time.now - @start_time ) > @seconds raise @exception, end false end |