Class: JLDrill::LevelStats
- Inherits:
-
Object
- Object
- JLDrill::LevelStats
- Defined in:
- lib/jldrill/model/Quiz/LevelStats.rb
Overview
Keeps track of statistics for a particular level were correct.
Instance Method Summary collapse
-
#accuracy ⇒ Object
Returns the percentage of items scored correctly.
-
#correct ⇒ Object
Indicate that a trial was correct.
-
#incorrect ⇒ Object
Indicate that a trial was incorrect.
-
#initialize ⇒ LevelStats
constructor
A new instance of LevelStats.
-
#total ⇒ Object
The total number of trials.
Constructor Details
#initialize ⇒ LevelStats
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
#accuracy ⇒ Object
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 |
#correct ⇒ Object
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 |
#incorrect ⇒ Object
Indicate that a trial was incorrect
19 20 21 |
# File 'lib/jldrill/model/Quiz/LevelStats.rb', line 19 def incorrect @num += 1 end |
#total ⇒ Object
The total number of trials
24 25 26 |
# File 'lib/jldrill/model/Quiz/LevelStats.rb', line 24 def total @num end |