Sha256: d3d7dec9b63ef81bc3c6be9c6367c98d6f153899177981627aa8aee49df398d9

Contents?: true

Size: 984 Bytes

Versions: 1

Compression:

Stored size: 984 Bytes

Contents

module JLDrill
    # Keeps track of statistics for a particular level
    # @num is the number of tries, @correct is the number that
    # were correct.
    class LevelStats
        def initialize
            @num = 0
            @correct = 0
        end
        
        # Indicate that a trial was correct    
        def correct
            @correct += 1
            @num += 1
        end
        
        # Indicate that a trial was incorrect    
        def incorrect
            @num += 1
        end
        
        # The total number of trials    
        def total
            @num
        end
        
        # 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.
        def accuracy
            if @num > 0
                ((@correct.to_f / @num.to_f) * 100).to_i
            else
                nil
            end
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jldrill-0.5.1.7 lib/jldrill/model/Quiz/LevelStats.rb