Class: JLDrill::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/jldrill/model/Quiz/Timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimer

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

#startedAtObject (readonly)

Returns the value of attribute startedAt.



4
5
6
# File 'lib/jldrill/model/Quiz/Timer.rb', line 4

def startedAt
  @startedAt
end

#totalObject (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

#resetObject



10
11
12
13
# File 'lib/jldrill/model/Quiz/Timer.rb', line 10

def reset
    @total = 0.0
    @startedAt = nil
end

#running?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/jldrill/model/Quiz/Timer.rb', line 25

def running?
    !@startedAt.nil?
end

#startObject



20
21
22
23
# File 'lib/jldrill/model/Quiz/Timer.rb', line 20

def start
    stop
    @startedAt = Time.now
end

#stopObject



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