Class: Timer

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

Constant Summary collapse

DEFAULT_OPTIONS =
{ :growl => true }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Timer

Returns a new instance of Timer.



10
11
12
13
14
# File 'lib/timer.rb', line 10

def initialize(options={})
  options = DEFAULT_OPTIONS.merge(options)
  @title = options[:title]
  @growl = options[:growl]
end

Instance Attribute Details

#growl=(value) ⇒ Object

Sets the attribute growl

Parameters:

  • value

    the value to set the attribute growl to.



6
7
8
# File 'lib/timer.rb', line 6

def growl=(value)
  @growl = value
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/timer.rb', line 6

def title
  @title
end

Instance Method Details

#growl?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/timer.rb', line 28

def growl?
  @growl
end

#time(message = "", options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/timer.rb', line 16

def time(message="", options={})
  current_title = options[:title] || title
  
  start_time = Time.now
  begin
    yield
  rescue StandardError => e
  end
  put_elapsed_time(start_time, Time.now, message, current_title)
  raise e if e
end