Class: JLDrill::Counter

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

Direct Known Subclasses

DurationCounter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCounter

Returns a new instance of Counter.



8
9
10
11
# File 'lib/jldrill/model/Quiz/Counter.rb', line 8

def initialize
    @ranges = makeRanges
    @table = initializeTable
end

Instance Attribute Details

#rangesObject (readonly)

Returns the value of attribute ranges.



6
7
8
# File 'lib/jldrill/model/Quiz/Counter.rb', line 6

def ranges
  @ranges
end

#tableObject (readonly)

Returns the value of attribute table.



6
7
8
# File 'lib/jldrill/model/Quiz/Counter.rb', line 6

def table
  @table
end

Class Method Details

.findRange(level) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/jldrill/model/Quiz/Counter.rb', line 29

def Counter.findRange(level)
    low = Duration.new(0)
    high = Duration.new
    high.days = 5.0
    1.upto(level) do
        low.assign(high)
        high.seconds = Schedule.backoff(low.seconds)
    end
    return low.seconds...high.seconds
end

.getLevel(item) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jldrill/model/Quiz/Counter.rb', line 40

def Counter.getLevel(item)
    level = 0
    found = false
    while (level <= 6) && !found
        range = Counter.findRange(level)
        if item.schedule.durationWithin?(range)
            found = true
        else
            level += 1
        end
    end
    return level
end

Instance Method Details

#initializeTableObject



13
14
15
16
17
18
19
# File 'lib/jldrill/model/Quiz/Counter.rb', line 13

def initializeTable
    retVal = []
    0.upto(7) do |level|
        retVal.push(0)
    end
    return retVal
end

#levelString(level) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/jldrill/model/Quiz/Counter.rb', line 60

def levelString(level)
    if level == 0
        return "Less than #{toDays(@ranges[0].end)} days"
    elsif level == 7
        return "More than #{toDays(@ranges[6].end)} days"
    else
        return "#{toDays(@ranges[level].begin)} to #{toDays(@ranges[level].end)} days"
    end
end

#makeRangesObject



21
22
23
24
25
26
27
# File 'lib/jldrill/model/Quiz/Counter.rb', line 21

def makeRanges
    retVal = []
    0.upto(6) do |level|
        retVal.push(Counter.findRange(level))
    end
    return retVal
end

#to_sObject



70
71
72
73
74
75
76
# File 'lib/jldrill/model/Quiz/Counter.rb', line 70

def to_s
    retVal = ""
    0.upto(7) do |i|
        retVal = retVal + levelString(i) + "    #{@table[i]}\n"
    end
    return retVal
end

#toDays(seconds) ⇒ Object

Returns the rounded number of days from seconds



55
56
57
58
# File 'lib/jldrill/model/Quiz/Counter.rb', line 55

def toDays(seconds) 
    d = Duration.new(seconds)
    return d.days.round
end