Class: Geoptima::Timer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Timer

Returns a new instance of Timer.



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

def initialize(name)
  @name = name
  reset
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



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

def end_time
  @end_time
end

#full_durationObject (readonly)

Returns the value of attribute full_duration.



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

def full_duration
  @full_duration
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#runningObject (readonly)

Returns the value of attribute running.



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

def running
  @running
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

Instance Method Details

#describeObject



33
34
35
# File 'lib/geoptima/timer.rb', line 33

def describe
  "#{name}\t#{full_duration}s"
end

#resetObject



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

def reset
  @running = false
  @duration = 0
  @full_duration = 0
  @start_time = nil
  @end_time = nil
end

#startObject



16
17
18
19
20
# File 'lib/geoptima/timer.rb', line 16

def start
  @duration = 0
  @running = true
  @start_time = Time.new
end

#stopObject



21
22
23
24
25
26
27
28
29
# File 'lib/geoptima/timer.rb', line 21

def stop
  if running
    @running = false
    @end_time = Time.new
    @duration = @end_time - @start_time
    @full_duration += @duration
  end
  @duration
end

#to_sObject



30
31
32
# File 'lib/geoptima/timer.rb', line 30

def to_s
  "#{name}(#{full_duration}s)"
end