Class: JLDrill::Timer
- Inherits:
-
Object
- Object
- JLDrill::Timer
- Defined in:
- lib/jldrill/model/Quiz/Timer.rb
Instance Attribute Summary collapse
-
#startedAt ⇒ Object
readonly
Returns the value of attribute startedAt.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #assign(timer) ⇒ Object
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
- #reset ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
6 7 8 |
# File 'lib/jldrill/model/Quiz/Timer.rb', line 6 def initialize reset end |
Instance Attribute Details
#startedAt ⇒ Object (readonly)
Returns the value of attribute startedAt.
4 5 6 |
# File 'lib/jldrill/model/Quiz/Timer.rb', line 4 def startedAt @startedAt end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
4 5 6 |
# File 'lib/jldrill/model/Quiz/Timer.rb', line 4 def total @total end |
Instance Method Details
#assign(timer) ⇒ Object
15 16 17 18 |
# File 'lib/jldrill/model/Quiz/Timer.rb', line 15 def assign(timer) @total = timer.total @startedAt = timer.startedAt end |
#reset ⇒ Object
10 11 12 13 |
# File 'lib/jldrill/model/Quiz/Timer.rb', line 10 def reset @total = 0.0 @startedAt = nil end |
#running? ⇒ Boolean
25 26 27 |
# File 'lib/jldrill/model/Quiz/Timer.rb', line 25 def running? !@startedAt.nil? end |
#start ⇒ Object
20 21 22 23 |
# File 'lib/jldrill/model/Quiz/Timer.rb', line 20 def start stop @startedAt = Time.now end |
#stop ⇒ Object
29 30 31 32 33 34 |
# File 'lib/jldrill/model/Quiz/Timer.rb', line 29 def stop if running? @total += Time.now.to_f - @startedAt.to_f @startedAt = nil end end |