Class: Timer

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

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Timer

Returns a new instance of Timer.



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

def initialize(options={})
  options ||= options
  @title = options[:title]
end

Instance Attribute Details

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Instance Method Details

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



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/timer.rb', line 12

def time(message="", options={})
  current_title = options[:title] || title

  start_time = Time.now
  begin
    yield
  rescue StandardError => e
    put_elapsed_time(start_time, Time.now, e.message, current_title)
  end
  put_elapsed_time(start_time, Time.now, message, current_title)
  raise e if e
end