Class: Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/waitfor/timer.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

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( options )
  @seconds = Timer.to_seconds options

  if options.instance_of? Hash
    @exception = options[ :exception ]
    @exception = options[ :error ] || @exception 
    @message   = options[ :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( options )
  # Not a hash, already converted to seconds, return as is
  return options if options.instance_of? Fixnum
  
  seconds = options[ :second ] || 0
  seconds = options[ :seconds ] || seconds

  minutes = options[ :minute ] || 0
  minutes = options[ :minutes ] || minutes

  return seconds + minutes * 60 
end

Instance Method Details

#out_of_time?Boolean

Returns:

  • (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, @message
  end

  false
end