Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/jldrill/model/Quiz/Options.rb | 293 | 254 | 83.96%
|
81.50%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 require 'jldrill/model/Config' |
2 require 'Context/Publisher' |
3 |
4 module JLDrill |
5 |
6 # Options for the standard quiz. |
7 class Options |
8 attr_reader :publisher, :randomOrder, :promoteThresh, :introThresh, |
9 :reviewMode, :dictionary, :reviewMeaning, |
10 :reviewKanji, :reviewReading, :reviewOptionsSet, |
11 :autoloadDic, :tanaka, :forgettingThresh |
12 |
13 RANDOM_ORDER_RE = /^Random Order/ |
14 PROMOTE_THRESH_RE = /^Promotion Threshold: (.*)/ |
15 INTRO_THRESH_RE = /^Introduction Threshold: (.*)/ |
16 DICTIONARY_RE = /^Dictionary: (.*)/ |
17 REVIEW_MEANING_RE = /^Review Meaning/ |
18 REVIEW_KANJI_RE = /^Review Kanji/ |
19 REVIEW_READING_RE = /^Review Reading/ |
20 AUTOLOAD_DIC_RE = /^Autoload Dictionary/ |
21 FORGETTING_THRESH_RE = /^Forgetting Threshold: (.*)/ |
22 |
23 def initialize(quiz) |
24 @quiz = quiz |
25 @publisher = Context::Publisher.new(self) |
26 @randomOrder = false |
27 @promoteThresh = 2 |
28 @introThresh = 10 |
29 @reviewMode = false |
30 @dictionary = nil |
31 @tanaka = nil |
32 @reviewOptionsSet = false |
33 @autoloadDic = false |
34 @forgettingThresh = 0.0 |
35 defaultReviewOptions |
36 end |
37 |
38 def clone |
39 retVal = Options.new(@quiz) |
40 retVal.randomOrder = @randomOrder |
41 retVal.promoteThresh = @promoteThresh |
42 retVal.introThresh = @introThresh |
43 retVal.reviewMode = @reviewMode |
44 retVal.dictionary = @dictionary |
45 setReviewOptions(@reviewOptionsSet) |
46 retVal.reviewMeaning = @reviewMeaning |
47 retVal.reviewKanji = @reviewKanji |
48 retVal.reviewReading = @reviewReading |
49 retVal.autoloadDic = @autoloadDic |
50 retVal.forgettingThresh = @forgettingThresh |
51 retVal |
52 end |
53 |
54 def eql?(options) |
55 options.randomOrder == @randomOrder && |
56 options.promoteThresh == @promoteThresh && |
57 options.introThresh == @introThresh && |
58 options.reviewMode == @reviewMode && |
59 options.dictionary == @dictionary && |
60 options.reviewOptionsSet == @reviewOptionsSet && |
61 options.reviewMeaning == @reviewMeaning && |
62 options.reviewKanji == @reviewKanji && |
63 options.autoloadDic == @autoloadDic && |
64 options.reviewReading == @reviewReading && |
65 options.forgettingThresh == @forgettingThresh |
66 end |
67 |
68 def subscribe(subscriber) |
69 @publisher.subscribe(subscriber, "options") |
70 end |
71 |
72 def unsubscribe(subscriber) |
73 @publisher.unsubscribe(subscriber, "options") |
74 end |
75 |
76 def update |
77 @publisher.update("options") |
78 end |
79 |
80 def saveNeeded |
81 @quiz.setNeedsSave(true) unless @quiz.nil? |
82 update |
83 end |
84 |
85 def modifiedButNoSaveNeeded |
86 @quiz.update unless @quiz.nil? |
87 update |
88 end |
89 |
90 # Assigns all the options from one to the other, but |
91 # does *keeps the same quiz* |
92 def assign(options) |
93 self.randomOrder = options.randomOrder |
94 self.promoteThresh = options.promoteThresh |
95 self.introThresh = options.introThresh |
96 self.dictionary = options.dictionary |
97 setReviewOptions(options.reviewOptionsSet) |
98 self.reviewMeaning = options.reviewMeaning |
99 self.reviewKanji = options.reviewKanji |
100 self.reviewReading = options.reviewReading |
101 self.autoloadDic = options.autoloadDic |
102 self.forgettingThresh = options.forgettingThresh |
103 if !@quiz.nil? |
104 @quiz.recreateProblem |
105 end |
106 end |
107 |
108 def randomOrder=(value) |
109 if @randomOrder != value |
110 @randomOrder = value |
111 saveNeeded |
112 end |
113 end |
114 |
115 def promoteThresh=(value) |
116 if @promoteThresh != value |
117 @promoteThresh = value |
118 saveNeeded |
119 end |
120 end |
121 |
122 def introThresh=(value) |
123 if @introThresh != value |
124 @introThresh = value |
125 saveNeeded |
126 end |
127 end |
128 |
129 # Note: Review Mode isn't saved so no save needed |
130 def reviewMode=(value) |
131 if @reviewMode != value |
132 @reviewMode = value |
133 modifiedButNoSaveNeeded |
134 end |
135 end |
136 |
137 def dictionary=(value) |
138 if @dictionary != value |
139 @dictionary = value |
140 saveNeeded |
141 end |
142 end |
143 |
144 def autoloadDic=(value) |
145 if @autoloadDic != value |
146 @autoloadDic = value |
147 saveNeeded |
148 end |
149 end |
150 |
151 def clearReviewOptions |
152 @reviewMeaning = false |
153 @reviewKanji = false |
154 @reviewReading = false |
155 saveNeeded |
156 end |
157 |
158 def defaultReviewOptions |
159 @reviewMeaning = true |
160 @reviewKanji = true |
161 @reviewReading = false |
162 saveNeeded |
163 end |
164 |
165 def setReviewOptions(value) |
166 if (value == true) |
167 if (@reviewOptionsSet == false) |
168 clearReviewOptions |
169 end |
170 else |
171 defaultReviewOptions |
172 end |
173 @reviewOptionsSet = value |
174 end |
175 |
176 def reviewMeaning=(value) |
177 setReviewOptions(true) |
178 if @reviewMeaning != value |
179 @reviewMeaning = value |
180 saveNeeded |
181 end |
182 end |
183 |
184 def reviewKanji=(value) |
185 setReviewOptions(true) |
186 if @reviewKanji != value |
187 @reviewKanji = value |
188 saveNeeded |
189 end |
190 end |
191 |
192 def reviewReading=(value) |
193 setReviewOptions(true) |
194 if @reviewReading != value |
195 @reviewReading = value |
196 saveNeeded |
197 end |
198 end |
199 |
200 def forgettingThresh=(value) |
201 if @forgettingThresh != value |
202 @forgettingThresh = value |
203 saveNeeded |
204 end |
205 end |
206 |
207 # Return an array containing the allowed levels for the |
208 # drills. |
209 def allowedLevels |
210 retVal = [] |
211 if reviewReading |
212 retVal.push(0) |
213 end |
214 if reviewKanji |
215 retVal.push(1) |
216 end |
217 if reviewMeaning |
218 retVal.push(2) |
219 end |
220 # If the user hasn't selected any levels, then |
221 # default to kanji and meaning |
222 if retVal.size == 0 |
223 retVal.push(1) |
224 retVal.push(2) |
225 end |
226 return retVal |
227 end |
228 |
229 def parseLine(line) |
230 parsed = true |
231 case line |
232 when RANDOM_ORDER_RE |
233 self.randomOrder = true |
234 when PROMOTE_THRESH_RE |
235 self.promoteThresh = $1.to_i |
236 when INTRO_THRESH_RE |
237 self.introThresh = $1.to_i |
238 when DICTIONARY_RE |
239 self.dictionary = $1.to_i |
240 when REVIEW_MEANING_RE |
241 self.reviewMeaning = $1.to_i |
242 when REVIEW_KANJI_RE |
243 self.reviewKanji = $1.to_i |
244 when REVIEW_READING_RE |
245 self.reviewReading = $1.to_i |
246 when AUTOLOAD_DIC_RE |
247 self.autoloadDic = true |
248 when FORGETTING_THRESH_RE |
249 self.forgettingThresh = $1.to_f |
250 else |
251 parsed = false |
252 end |
253 parsed |
254 end |
255 |
256 # Return a string showing the current state of the options |
257 def status |
258 retVal = "" |
259 if(@randomOrder) then retVal += "R" end |
260 retVal += "(#{@promoteThresh},#{@introThresh})" |
261 retVal |
262 end |
263 |
264 def to_s |
265 retVal = "" |
266 if(@randomOrder) |
267 retVal += "Random Order\n" |
268 end |
269 retVal += "Promotion Threshold: #{@promoteThresh}\n" |
270 retVal += "Introduction Threshold: #{@introThresh}\n" |
271 if(!@dictionary.nil?) |
272 retVal += "Dictionary: #{@dictionary}\n" |
273 end |
274 if(@reviewMeaning) |
275 retVal += "Review Meaning\n" |
276 end |
277 if(@reviewKanji) |
278 retVal += "Review Kanji\n" |
279 end |
280 if(@reviewReading) |
281 retVal += "Review Reading\n" |
282 end |
283 if(@autoloadDic) |
284 retVal += "Autoload Dictionary\n" |
285 end |
286 if(@forgettingThresh != 0) |
287 retVal += "Forgetting Threshold: #{@forgettingThresh}\n" |
288 end |
289 retVal |
290 end |
291 end |
292 end |
293 |
Generated on Mon May 23 16:17:46 +0900 2011 with rcov 0.9.8