Class: JLDrill::Options

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

Overview

Options for the standard quiz.

Constant Summary collapse

RANDOM_ORDER_RE =
/^Random Order/
PROMOTE_THRESH_RE =
/^Promotion Threshold: (.*)/
INTRO_THRESH_RE =
/^Introduction Threshold: (.*)/
DICTIONARY_RE =
/^Dictionary: (.*)/
LANGUAGE_RE =
/^Language: (.*)/
REVIEW_MEANING_RE =
/^Review Meaning/
REVIEW_KANJI_RE =
/^Review Kanji/
REVIEW_READING_RE =
/^Review Reading/
AUTOLOAD_DIC_RE =
/^Autoload Dictionary/
FORGETTING_THRESH_RE =
/^Forgetting Threshold: (.*)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(quiz) ⇒ Options

Returns a new instance of Options.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jldrill/model/Quiz/Options.rb', line 25

def initialize(quiz)
    @quiz = quiz
    @publisher = Context::Publisher.new(self)
    @randomOrder = false
    @promoteThresh = 2
    @introThresh = 10
    @reviewMode = false
			@dictionary = nil
    @language = "Japanese"
			@tanaka = nil
    @reviewOptionsSet = false
    @autoloadDic = false
    @forgettingThresh = 0.0
    defaultReviewOptions
end

Instance Attribute Details

#autoloadDicObject

Returns the value of attribute autoloadDic.



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

def autoloadDic
  @autoloadDic
end

#dictionaryObject

Returns the value of attribute dictionary.



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

def dictionary
  @dictionary
end

#forgettingThreshObject

Returns the value of attribute forgettingThresh.



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

def forgettingThresh
  @forgettingThresh
end

#introThreshObject

Returns the value of attribute introThresh.



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

def introThresh
  @introThresh
end

#languageObject

Returns the value of attribute language.



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

def language
  @language
end

#promoteThreshObject

Returns the value of attribute promoteThresh.



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

def promoteThresh
  @promoteThresh
end

#publisherObject (readonly)

Returns the value of attribute publisher.



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

def publisher
  @publisher
end

#randomOrderObject

Returns the value of attribute randomOrder.



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

def randomOrder
  @randomOrder
end

#reviewKanjiObject

Returns the value of attribute reviewKanji.



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

def reviewKanji
  @reviewKanji
end

#reviewMeaningObject

Returns the value of attribute reviewMeaning.



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

def reviewMeaning
  @reviewMeaning
end

#reviewModeObject

Returns the value of attribute reviewMode.



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

def reviewMode
  @reviewMode
end

#reviewOptionsSetObject (readonly)

Returns the value of attribute reviewOptionsSet.



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

def reviewOptionsSet
  @reviewOptionsSet
end

#reviewReadingObject

Returns the value of attribute reviewReading.



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

def reviewReading
  @reviewReading
end

#tanakaObject (readonly)

Returns the value of attribute tanaka.



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

def tanaka
  @tanaka
end

Instance Method Details

#allowedLevelsObject

Return an array containing the allowed levels for the drills.



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/jldrill/model/Quiz/Options.rb', line 222

def allowedLevels
    retVal = []
    if reviewReading
        retVal.push(0)
    end
    if reviewKanji
        retVal.push(1)
    end
    if reviewMeaning
        retVal.push(2)
    end
    # If the user hasn't selected any levels, then
    # default to kanji and meaning
    if retVal.size == 0
        retVal.push(1)
        retVal.push(2)
    end
    return retVal
end

#assign(options) ⇒ Object

Assigns all the options from one to the other, but does *keeps the same quiz*



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/jldrill/model/Quiz/Options.rb', line 97

def assign(options)
    self.randomOrder = options.randomOrder
    self.promoteThresh = options.promoteThresh
    self.introThresh = options.introThresh
    self.dictionary = options.dictionary
    self.language = options.language
    setReviewOptions(options.reviewOptionsSet)
    self.reviewMeaning = options.reviewMeaning
    self.reviewKanji = options.reviewKanji
    self.reviewReading = options.reviewReading
    self.autoloadDic = options.autoloadDic
    self.forgettingThresh = options.forgettingThresh
    if !@quiz.nil?
        @quiz.recreateProblem
    end
end

#clearReviewOptionsObject



164
165
166
167
168
169
# File 'lib/jldrill/model/Quiz/Options.rb', line 164

def clearReviewOptions
    @reviewMeaning = false
    @reviewKanji = false
    @reviewReading = false
    saveNeeded
end

#cloneObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jldrill/model/Quiz/Options.rb', line 41

def clone
    retVal = Options.new(@quiz)
    retVal.randomOrder = @randomOrder
    retVal.promoteThresh = @promoteThresh
    retVal.introThresh = @introThresh
    retVal.reviewMode = @reviewMode
    retVal.dictionary = @dictionary
    retVal.language = @language
    setReviewOptions(@reviewOptionsSet)
    retVal.reviewMeaning = @reviewMeaning
    retVal.reviewKanji = @reviewKanji
    retVal.reviewReading = @reviewReading
    retVal.autoloadDic = @autoloadDic
    retVal.forgettingThresh = @forgettingThresh
    retVal
end

#defaultReviewOptionsObject



171
172
173
174
175
176
# File 'lib/jldrill/model/Quiz/Options.rb', line 171

def defaultReviewOptions
    @reviewMeaning = true
    @reviewKanji = true
    @reviewReading = false
    saveNeeded
end

#eql?(options) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/jldrill/model/Quiz/Options.rb', line 58

def eql?(options)
    options.randomOrder == @randomOrder &&
    options.promoteThresh == @promoteThresh &&
    options.introThresh == @introThresh &&
    options.reviewMode == @reviewMode &&
    options.dictionary == @dictionary &&
    options.language == @language &&
    options.reviewOptionsSet == @reviewOptionsSet &&
    options.reviewMeaning == @reviewMeaning &&
    options.reviewKanji == @reviewKanji &&
    options.autoloadDic == @autoloadDic &&
    options.reviewReading == @reviewReading &&
    options.forgettingThresh == @forgettingThresh
end

#modifiedButNoSaveNeededObject



90
91
92
93
# File 'lib/jldrill/model/Quiz/Options.rb', line 90

def modifiedButNoSaveNeeded
    @quiz.update unless @quiz.nil?
    update
end

#parseLine(line) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/jldrill/model/Quiz/Options.rb', line 242

def parseLine(line)
    parsed = true
    case line
        when RANDOM_ORDER_RE
            self.randomOrder = true
        when PROMOTE_THRESH_RE
            self.promoteThresh = $1.to_i
        when INTRO_THRESH_RE 
            self.introThresh = $1.to_i
				when DICTIONARY_RE
					self.dictionary = $1
				when LANGUAGE_RE
					self.language = $1
        when REVIEW_MEANING_RE
            self.reviewMeaning = $1.to_i
        when REVIEW_KANJI_RE
            self.reviewKanji = $1.to_i
        when REVIEW_READING_RE
            self.reviewReading = $1.to_i
        when AUTOLOAD_DIC_RE
            self.autoloadDic = true
        when FORGETTING_THRESH_RE
            self.forgettingThresh = $1.to_f
        else
            parsed = false
    end
    parsed
end

#saveNeededObject



85
86
87
88
# File 'lib/jldrill/model/Quiz/Options.rb', line 85

def saveNeeded
    @quiz.setNeedsSave(true) unless @quiz.nil?
    update
end

#setReviewOptions(value) ⇒ Object



178
179
180
181
182
183
184
185
186
187
# File 'lib/jldrill/model/Quiz/Options.rb', line 178

def setReviewOptions(value)
    if (value == true) 
        if (@reviewOptionsSet == false)
            clearReviewOptions
        end
    else
        defaultReviewOptions
    end
    @reviewOptionsSet = value
end

#statusObject

Return a string showing the current state of the options



272
273
274
275
276
277
# File 'lib/jldrill/model/Quiz/Options.rb', line 272

def status
    retVal = ""
    if(@randomOrder) then retVal += "R" end
    retVal += "(#{@promoteThresh},#{@introThresh})"
    retVal
end

#subscribe(subscriber) ⇒ Object



73
74
75
# File 'lib/jldrill/model/Quiz/Options.rb', line 73

def subscribe(subscriber)
    @publisher.subscribe(subscriber, "options")
end

#to_sObject



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/jldrill/model/Quiz/Options.rb', line 279

def to_s
    retVal = ""
    if(@randomOrder)
        retVal += "Random Order\n"
    end
    retVal += "Promotion Threshold: #{@promoteThresh}\n"
    retVal += "Introduction Threshold: #{@introThresh}\n"
			if(!@dictionary.nil?)
				retVal += "Dictionary: #{@dictionary}\n"
			end
    if(@language != "Japanese")
        retVal += "Language: #{@language}\n"
    end
    if(@reviewMeaning)
        retVal += "Review Meaning\n"
    end
    if(@reviewKanji)
        retVal += "Review Kanji\n"
    end
    if(@reviewReading)
        retVal += "Review Reading\n"
    end
    if(@autoloadDic)
        retVal += "Autoload Dictionary\n"
    end
    if(@forgettingThresh != 0)
        retVal += "Forgetting Threshold: #{@forgettingThresh}\n"
    end
    retVal
end

#unsubscribe(subscriber) ⇒ Object



77
78
79
# File 'lib/jldrill/model/Quiz/Options.rb', line 77

def unsubscribe(subscriber)
    @publisher.unsubscribe(subscriber, "options")
end

#updateObject



81
82
83
# File 'lib/jldrill/model/Quiz/Options.rb', line 81

def update
    @publisher.update("options")
end