Class: Allotment::Stopwatch
- Inherits:
-
Object
- Object
- Allotment::Stopwatch
- Defined in:
- lib/allotment/stopwatch.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(name = nil) ⇒ Stopwatch
constructor
A new instance of Stopwatch.
- #lap ⇒ Object
- #reset ⇒ Object
- #split ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/allotment/stopwatch.rb', line 3 def name @name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
3 4 5 |
# File 'lib/allotment/stopwatch.rb', line 3 def status @status end |
Instance Method Details
#lap ⇒ Object
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 |
#reset ⇒ Object
22 23 24 25 |
# File 'lib/allotment/stopwatch.rb', line 22 def reset @start_time = Time.now @current_time = nil end |
#split ⇒ Object
33 34 35 |
# File 'lib/allotment/stopwatch.rb', line 33 def split Time.now - @start_time end |
#start ⇒ Object
12 13 14 15 |
# File 'lib/allotment/stopwatch.rb', line 12 def start @start_time = Time.now - (@current_time || 0) @status = 'running' end |
#stop ⇒ Object
17 18 19 20 |
# File 'lib/allotment/stopwatch.rb', line 17 def stop @status = 'stopped' @current_time = Time.now - @start_time end |