Class: Allotment::Stopwatch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Stopwatch

Returns a new instance of Stopwatch.



5
6
7
8
9
10
# File 'lib/allotment/stopwatch.rb', line 5

def initialize name = nil
	@stopwatch  = self.class.uniqe_name
	@name       = name || @stopwatch
	@status     = 'running'
	@start_time = Time.now
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/allotment/stopwatch.rb', line 3

def name
  @name
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/allotment/stopwatch.rb', line 3

def status
  @status
end

Instance Method Details

#lapObject



27
28
29
30
31
# File 'lib/allotment/stopwatch.rb', line 27

def lap
	@new_lap = Time.now - (@lap_time || @start_time)
	@lap_time = Time.now
	return @new_lap
end

#resetObject



22
23
24
25
# File 'lib/allotment/stopwatch.rb', line 22

def reset
	@start_time 	= Time.now
	@current_time = nil
end

#splitObject



33
34
35
# File 'lib/allotment/stopwatch.rb', line 33

def split
	Time.now - @start_time
end

#startObject



12
13
14
15
# File 'lib/allotment/stopwatch.rb', line 12

def start
	@start_time = Time.now - (@current_time || 0)
	@status     = 'running'
end

#stopObject



17
18
19
20
# File 'lib/allotment/stopwatch.rb', line 17

def stop
	@status       = 'stopped'
	@current_time = Time.now - @start_time
end