Class: JLDrill::LevelStats

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

Overview

Keeps track of statistics for a particular level were correct.

Instance Method Summary collapse

Constructor Details

#initializeLevelStats

Returns a new instance of LevelStats.



7
8
9
10
# File 'lib/jldrill/model/Quiz/LevelStats.rb', line 7

def initialize
    @num = 0
    @correct = 0
end

Instance Method Details

#accuracyObject

Returns the percentage of items scored correctly. Note this returns an integer from 0 to 100. If the percentage included a fraction, the fraction is truncated.



31
32
33
34
35
36
37
# File 'lib/jldrill/model/Quiz/LevelStats.rb', line 31

def accuracy
    if @num > 0
        ((@correct.to_f / @num.to_f) * 100).to_i
    else
        nil
    end
end

#correctObject

Indicate that a trial was correct



13
14
15
16
# File 'lib/jldrill/model/Quiz/LevelStats.rb', line 13

def correct
    @correct += 1
    @num += 1
end

#incorrectObject

Indicate that a trial was incorrect



19
20
21
# File 'lib/jldrill/model/Quiz/LevelStats.rb', line 19

def incorrect
    @num += 1
end

#totalObject

The total number of trials



24
25
26
# File 'lib/jldrill/model/Quiz/LevelStats.rb', line 24

def total
    @num
end