Sha256: 9f4ef117b2f9490bbd8429637dd13bac3eaad07a7f9ed9d9c85d8e580914a6d3

Contents?: true

Size: 1002 Bytes

Versions: 1

Compression:

Stored size: 1002 Bytes

Contents

# encoding: utf-8
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.6.0.1 lib/jldrill/model/Quiz/LevelStats.rb