Class: JLDrill::Quiz
Constant Summary
collapse
/^(\d+\.\d+\.\d+)?-?LDRILL-SAVE (.*)/
/^\#[ ]?(.*)/
- VERSION_RE =
/^(\d+)\.(\d+)\.(\d+)/
- JLDRILL_CANLOAD_RE =
/^(\d+\.\d+\.\d+)?-?LDRILL-SAVE/
Instance Attribute Summary collapse
Attributes inherited from DataFile
#encoding, #file, #lines, #parsed, #publisher, #stepSize
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from DataFile
#createLines, #eof?, #findEncoding, #fraction, #load, #loaded?, #parse, #parseChunk, #parser, #readLines, #shortFilename
Constructor Details
#initialize ⇒ Quiz
Returns a new instance of Quiz.
24
25
26
27
28
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 24
def initialize()
super
@stepSize = 10
end
|
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
19
20
21
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 19
def contents
@contents
end
|
#currentProblem ⇒ Object
Returns the value of attribute currentProblem.
19
20
21
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 19
def currentProblem
@currentProblem
end
|
#info ⇒ Object
Returns the value of attribute info.
19
20
21
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 19
def info
@info
end
|
#name ⇒ Object
Returns the value of attribute name.
19
20
21
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 19
def name
@name
end
|
#needsSave ⇒ Object
Returns the value of attribute needsSave.
19
20
21
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 19
def needsSave
@needsSave
end
|
#options ⇒ Object
Returns the value of attribute options.
19
20
21
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 19
def options
@options
end
|
#strategy ⇒ Object
Returns the value of attribute strategy.
19
20
21
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 19
def strategy
@strategy
end
|
Class Method Details
.canLoad?(header) ⇒ Boolean
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 160
def Quiz.canLoad?()
retVal = false
if =~ JLDRILL_CANLOAD_RE
if $1 != ""
if $1 =~ VERSION_RE
if $1.to_i > 0 || $2.to_i < 7
retVal = true
end
end
end
end
return retVal
end
|
.drillFile?(file) ⇒ Boolean
174
175
176
177
178
179
180
181
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 174
def Quiz.drillFile?(file)
retVal = false
loadFile = File.new(file, "r")
if(loadFile)
retVal = Quiz.canLoad?(loadFile.readline)
end
return retVal
end
|
Instance Method Details
#allItems ⇒ Object
Get an array containing all the items in the quiz
304
305
306
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 304
def allItems
@contents.allItems
end
|
#answer ⇒ Object
390
391
392
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 390
def answer()
@currentProblem.answer
end
|
#append(quiz) ⇒ Object
Append any new items in the quiz to this quiz Note: Does not add items that are already existing.
nor does it update the status of existing items
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 254
def append(quiz)
@publisher.block
lastItem = @contents.addContents(quiz.contents)
@publisher.unblock
update
updateLoad
updateItemAdded(lastItem) unless lastItem.nil?
if @currentProblem.nil?
drill
end
end
|
#appendVocab(vocab) ⇒ Object
282
283
284
285
286
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 282
def appendVocab(vocab)
item = Item.new(vocab)
@contents.addUniquely(item)
return item
end
|
#bin ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 51
def bin
retVal = nil
if !@currentProblem.nil?
retVal = @currentProblem.item.bin
end
retVal
end
|
#correct ⇒ Object
330
331
332
333
334
335
336
337
338
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 330
def correct
if !@currentProblem.nil?
item = @currentProblem.item
if !item.nil?
@strategy.correct(item)
setNeedsSave(true)
end
end
end
|
#createProblem(item) ⇒ Object
Creates a problem to be quizzed
360
361
362
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 360
def createProblem(item)
setCurrentProblem(@strategy.createProblem(item))
end
|
#currentAnswer ⇒ Object
398
399
400
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 398
def currentAnswer
@currentProblem.answer
end
|
#currentDrill ⇒ Object
394
395
396
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 394
def currentDrill
@currentProblem.question
end
|
#dataSize ⇒ Object
211
212
213
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 211
def dataSize
@contents.size
end
|
#deleteItem(item) ⇒ Object
Delete an item from the quiz
315
316
317
318
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 315
def deleteItem(item)
@contents.delete(item)
updateItemDeleted(item)
end
|
#displayProblem(item) ⇒ Object
Creates a problem to be displayed only
365
366
367
368
369
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 365
def displayProblem(item)
problem = @strategy.createProblem(item)
problem.setDisplayOnly(true)
setCurrentProblem(problem)
end
|
#drill ⇒ Object
383
384
385
386
387
388
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 383
def drill()
item = @strategy.getItem
if !item.nil?
createProblem(item)
end
end
|
#exists?(vocab) ⇒ Boolean
Returns true if the vocabulary already exists in the Quiz
278
279
280
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 278
def exists?(vocab)
@contents.exists?(vocab)
end
|
114
115
116
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 114
def
JLDrill::VERSION + "-LDRILL-SAVE #{@name}\n"
end
|
#finishParsing ⇒ Object
215
216
217
218
219
220
221
222
223
224
225
226
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 215
def finishParsing
@strategy.newSet.sort! do |x, y|
x.position <=> y.position
end
reschedule
setNeedsSave(true)
update
super
end
|
#incorrect ⇒ Object
320
321
322
323
324
325
326
327
328
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 320
def incorrect
if !@currentProblem.nil?
item = @currentProblem.item
if !item.nil?
@strategy.incorrect(item)
setNeedsSave(true)
end
end
end
|
#learn ⇒ Object
Promote the current problem into the review set if it is in the working set without any further practice.
343
344
345
346
347
348
349
350
351
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 343
def learn
if !@currentProblem.nil?
item = @currentProblem.item
if !item.nil?
@strategy.learn(item)
setNeedsSave(true)
end
end
end
|
#length ⇒ Object
43
44
45
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 43
def length
@contents.length
end
|
#loadFromDict(dict) ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 235
def loadFromDict(dict)
if dict
@publisher.block
reset
@name = dict.shortFilename
dict.eachVocab do |vocab|
@contents.add(vocab, 0)
end
reschedule
@publisher.unblock
setNeedsSave(true)
end
end
|
#loadFromString(file, string) ⇒ Object
228
229
230
231
232
233
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 228
def loadFromString(file, string)
reset
@file = file
@lines = string.split("\n")
parse
end
|
#needsSave? ⇒ Boolean
110
111
112
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 110
def needsSave?
@needsSave
end
|
#parseEntry ⇒ Object
206
207
208
209
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 206
def parseEntry
parseLine(@lines[@parsed])
@parsed += 1
end
|
#parseLine(line) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 183
def parseLine(line)
if !@contents.parseLine(line)
if !@options.parseLine(line)
case line
when JLDRILL_HEADER_RE
@name = $2
when COMMENT_RE
@info += $1 + "\n"
else
end
end
end
end
|
#previewProblem(item) ⇒ Object
Creates a preview for a problem
372
373
374
375
376
377
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 372
def previewProblem(item)
problem = @strategy.createProblem(item)
problem.setDisplayOnly(true)
problem.setPreview(true)
setCurrentProblem(problem)
end
|
#problemModified(problem) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 93
def problemModified(problem)
@publisher.update("problemModified", problem)
setNeedsSave(true)
if !problem.valid? &&
!@currentProblem.nil? && (problem == @currentProblem)
recreateProblem
end
end
|
#recreateProblem ⇒ Object
379
380
381
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 379
def recreateProblem
createProblem(@currentProblem.item) unless @currentProblem.nil?
end
|
#reschedule ⇒ Object
Sort the items in the ReviewSet according to their schedule
273
274
275
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 273
def reschedule
@strategy.reschedule
end
|
#reset ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 30
def reset
@name = ""
@info = ""
@options = Options.new(self)
@contents = Contents.new(self)
@strategy = Strategy.new(self)
@currentProblem = nil
@needsSave = false
@last = nil
update
super
end
|
#resetContents ⇒ Object
Resets the quiz back to it’s original state
309
310
311
312
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 309
def resetContents
@contents.reset()
drill()
end
|
#save ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 128
def save
if (@contents.length == 0) || !@needsSave
return true
elsif @file == ""
return false
else
begin
saveFile = File.new(@file, "w")
if saveFile
saveFile.print(saveToString)
saveFile.close
setNeedsSave(false)
retVal = true
end
rescue
return false
end
end
end
|
#saveToString ⇒ Object
118
119
120
121
122
123
124
125
126
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 118
def saveToString
retVal =
@info.split("\n").each { |line|
retVal += "# " + line + "\n"
}
retVal += @options.to_s
retVal += @contents.to_s
retVal
end
|
#setCurrentProblem(problem) ⇒ Object
353
354
355
356
357
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 353
def setCurrentProblem(problem)
@currentProblem = problem
update
updateNewProblem(@currentProblem)
end
|
#setLoaded(bool) ⇒ Object
75
76
77
78
79
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 75
def setLoaded(bool)
if bool
updateLoad
end
end
|
#setNeedsSave(bool) ⇒ Object
105
106
107
108
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 105
def setNeedsSave(bool)
@needsSave = bool
update
end
|
#size ⇒ Object
47
48
49
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 47
def size
length
end
|
#status ⇒ Object
288
289
290
291
292
293
294
295
296
297
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 288
def status
retVal = ""
if(@needsSave) then retVal += "* " else retVal += " " end
retVal += @contents.status + " "
if !@currentProblem.nil?
retVal += @currentProblem.status + " "
end
retVal += @strategy.status
return retVal
end
|
#subscribe(subscriber) ⇒ Object
59
60
61
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 59
def subscribe(subscriber)
@publisher.subscribe(subscriber, "quiz")
end
|
#to_s ⇒ Object
299
300
301
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 299
def to_s
status
end
|
#unsubscribe(subscriber) ⇒ Object
63
64
65
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 63
def unsubscribe(subscriber)
@publisher.unsubscribe(subscriber, "quiz")
end
|
#update ⇒ Object
67
68
69
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 67
def update
@publisher.update("quiz")
end
|
#updateItemAdded(item) ⇒ Object
85
86
87
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 85
def updateItemAdded(item)
@publisher.update("itemAdded", item)
end
|
#updateItemDeleted(item) ⇒ Object
81
82
83
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 81
def updateItemDeleted(item)
@publisher.update("itemDeleted", item)
end
|
#updateLoad ⇒ Object
71
72
73
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 71
def updateLoad
@publisher.update("load")
end
|
#updateNewProblem(problem) ⇒ Object
89
90
91
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 89
def updateNewProblem(problem)
@publisher.update("newProblem", problem)
end
|
#useSavePath(filename) ⇒ Object
Returns the filename relative to the Quiz’s current path. If a filename hasn’t been set, the file is expanded using the applications current path.
151
152
153
154
155
156
157
158
|
# File 'lib/jldrill/model/Quiz/Quiz.rb', line 151
def useSavePath(filename)
if !@file.empty?
dirname = File.expand_path(File.dirname(@file))
return File.expand_path(filename, dirname)
else
return File.expand_path(filename)
end
end
|