Class: JLDrill::ProblemStatus

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

Overview

Keeps track of which problem types are being reviewed and their schedules

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ ProblemStatus

Returns a new instance of ProblemStatus.



13
14
15
16
17
# File 'lib/jldrill/model/ProblemStatus.rb', line 13

def initialize(item)
    @item = item
    @types = []
    @schedules = []
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



10
11
12
# File 'lib/jldrill/model/ProblemStatus.rb', line 10

def item
  @item
end

#schedulesObject (readonly)

Returns the value of attribute schedules.



10
11
12
# File 'lib/jldrill/model/ProblemStatus.rb', line 10

def schedules
  @schedules
end

#typesObject (readonly)

Returns the value of attribute types.



10
11
12
# File 'lib/jldrill/model/ProblemStatus.rb', line 10

def types
  @types
end

Instance Method Details

#addAllowed(levels) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/jldrill/model/ProblemStatus.rb', line 77

def addAllowed(levels)
    levels.each do |level|
        type = ProblemFactory.lookup(level)
        if findSchedule(type).nil?
            # If it can't find the correct type of schedule,
            # duplicate the first one it find and add it.
            addScheduleType(type, firstSchedule.clone)
        end
    end 
end

#addScheduleType(type, schedule) ⇒ Object



38
39
40
41
42
43
# File 'lib/jldrill/model/ProblemStatus.rb', line 38

def addScheduleType(type, schedule)
    if (type != "KanjiProblem") || (@item.hasKanji?)
        @schedules.push(schedule)
        @types.push(type)
    end
end

#allCorrectObject



160
161
162
163
164
# File 'lib/jldrill/model/ProblemStatus.rb', line 160

def allCorrect
    @schedules.each do |schedule|
        schedule.correct
    end
end

#allIncorrectObject



166
167
168
169
170
# File 'lib/jldrill/model/ProblemStatus.rb', line 166

def allIncorrect
    @schedules.each do |schedule|
        schedule.incorrect
    end            
end

#allSeen(value) ⇒ Object



142
143
144
145
146
# File 'lib/jldrill/model/ProblemStatus.rb', line 142

def allSeen(value)
    @schedules.each do |schedule|
        schedule.seen = value
    end
end

#assign(value) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/jldrill/model/ProblemStatus.rb', line 29

def assign(value)
    value.types.each do |type|
        @types.push(type)
    end
    value.schedules.each do |schedule|
        @schedules.push(schedule.clone)
    end
end

#checkSchedulesObject

Make sure the schedule types match with the allowed ones for the quiz. If not, push a new type on.



125
126
127
128
129
130
131
# File 'lib/jldrill/model/ProblemStatus.rb', line 125

def checkSchedules
    if !@item.nil? && !@item.quiz.nil?
        levels = @item.quiz.options.allowedLevels
        addAllowed(levels)
        removeDisallowed(levels)
    end
end

#cloneObject



23
24
25
26
27
# File 'lib/jldrill/model/ProblemStatus.rb', line 23

def clone
    retVal = ProblemStatus.new(item)
    retVal.assign(self)
    return retVal
end

#currentlyParsingObject



194
195
196
# File 'lib/jldrill/model/ProblemStatus.rb', line 194

def currentlyParsing
    @types.size - 1
end

#demoteAllObject

When an item is being demoted, demote all the schedules



89
90
91
92
93
# File 'lib/jldrill/model/ProblemStatus.rb', line 89

def demoteAll
    @schedules.each do |schedule|
        schedule.demote
    end
end

#disallowed?(type, levels) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
109
110
# File 'lib/jldrill/model/ProblemStatus.rb', line 103

def disallowed?(type, levels)
    retVal = false
    index = ProblemFactory.parse(type)
    if !index.nil?
        retVal = !levels.include?(index)
    end
    return retVal
end

#findSchedule(type) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/jldrill/model/ProblemStatus.rb', line 68

def findSchedule(type)
    sched = nil
    index = @types.find_index(type)
    if !index.nil?
        sched = @schedules[index]
    end
    return sched
end

#firstProblemObject



172
173
174
175
176
177
178
179
180
181
# File 'lib/jldrill/model/ProblemStatus.rb', line 172

def firstProblem
    # Every time we make a problem we should check to make sure
    # that correct schedules have been build.  The user may have
    # changed the options.
    checkSchedules
    sched = firstSchedule
    index = @schedules.find_index(sched)
    level = ProblemFactory.parse(@types[index])
    return ProblemFactory.create(level, @item)
end

#firstScheduleObject

Returns the schedule that should be addressed first



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/jldrill/model/ProblemStatus.rb', line 56

def firstSchedule
    retVal = @schedules.min do |x,y|
        x.reviewLoad <=> y.reviewLoad
    end
    # If there is no schedule, then create a meaning problem schedule
    if retVal.nil?
        retVal = Schedule.new(@item)
        addScheduleType("MeaningProblem", retVal)
    end
    return retVal
end

#nameObject



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

def name
    return "ProblemStatus"
end

#parse(part) ⇒ Object



224
225
226
227
228
229
230
# File 'lib/jldrill/model/ProblemStatus.rb', line 224

def parse(part)
    retVal = parseType(part)
    if !retVal
        retVal = parseSchedule(part)
    end
    return retVal
end

#parseSchedule(part) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/jldrill/model/ProblemStatus.rb', line 208

def parseSchedule(part)
    retVal = false
    if currentlyParsing == -1
        # Create a temporary schedule
        sched = Schedule.new(@item)
        if sched.parse(part)
            @types.push("MeaningProblem")
            @schedules.push(sched)
            retVal = true
        end
    else
        retVal = @schedules[currentlyParsing].parse(part)
    end
    return retVal
end

#parseType(part) ⇒ Object



198
199
200
201
202
203
204
205
206
# File 'lib/jldrill/model/ProblemStatus.rb', line 198

def parseType(part)
    retVal = false
    if !ProblemFactory.parse(part).nil?
        @types.push(part)
        @schedules.push(Schedule.new(@item))
        retVal = true
    end
    return retVal
end

#removeDisallowed(levels) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'lib/jldrill/model/ProblemStatus.rb', line 112

def removeDisallowed(levels)
    @types.each_index do |i|
        if disallowed?(@types[i], levels)
            @schedules.delete_at(i)
        end
    end
    @types.delete_if do |type|
        disallowed?(type, levels)
    end
end

#removeInvalidKanjiProblemsObject

This is here for legacy files that might have added schedules for KanjiProblems that they don’t have



47
48
49
50
51
52
53
# File 'lib/jldrill/model/ProblemStatus.rb', line 47

def removeInvalidKanjiProblems
    pos = @types.find_index("KanjiProblem")
    if !pos.nil? && !@item.hasKanji?
        @types.delete_at(pos)
        @schedules.delete_at(pos)
    end
end

#resetAllObject



133
134
135
136
137
138
139
140
# File 'lib/jldrill/model/ProblemStatus.rb', line 133

def resetAll
    # First check to make sure that there are the correct
    # schedules.
    checkSchedules
    @schedules.each do |schedule|
        schedule.reset
    end
end

#scheduleAllObject

When an item is being promoted to the review set, schedule each type



97
98
99
100
101
# File 'lib/jldrill/model/ProblemStatus.rb', line 97

def scheduleAll
    @schedules.each do |schedule|
        schedule.schedule
    end
end

#setLevels(value) ⇒ Object



154
155
156
157
158
# File 'lib/jldrill/model/ProblemStatus.rb', line 154

def setLevels(value)
    @schedules.each do |schedule|
        schedule.level = value
    end
end

#setScores(value) ⇒ Object



148
149
150
151
152
# File 'lib/jldrill/model/ProblemStatus.rb', line 148

def setScores(value)
    @schedules.each do |schedule|
        schedule.score = value
    end
end

#to_sObject



183
184
185
186
187
188
189
190
191
192
# File 'lib/jldrill/model/ProblemStatus.rb', line 183

def to_s
    retVal = ""
    0.upto(@types.size - 1) do |i|
        retVal += "/" + @types[i]
        if i < @schedules.size
            retVal += @schedules[i].to_s
        end
    end
    return retVal
end