Class: JLDrill::Problem

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

Overview

Represents a single question/answer pair in a quiz

Direct Known Subclasses

KanjiProblem, MeaningProblem, ReadingProblem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ Problem

Returns a new instance of Problem.



10
11
12
13
14
15
16
17
18
19
# File 'lib/jldrill/model/Problem.rb', line 10

def initialize(item)
    @item = item
    @level = -1
    @requestedLevel = -1
    @questionParts = []
    @answerParts = []
    @vocab = item.to_o
    @displayOnly = false
    @preview = false
end

Instance Attribute Details

#answerPartsObject (readonly)

Returns the value of attribute answerParts.



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

def answerParts
  @answerParts
end

#itemObject (readonly)

Returns the value of attribute item.



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

def item
  @item
end

#levelObject (readonly)

Returns the value of attribute level.



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

def level
  @level
end

#questionPartsObject (readonly)

Returns the value of attribute questionParts.



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

def questionParts
  @questionParts
end

#requestedLevelObject

Returns the value of attribute requestedLevel.



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

def requestedLevel
  @requestedLevel
end

Instance Method Details

#answerObject



146
147
148
# File 'lib/jldrill/model/Problem.rb', line 146

def answer
    evaluateParts(@answerParts)
end

#assign(value) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/jldrill/model/Problem.rb', line 26

def assign(value)
    @item = value.item
    @level = value.level
    @requestedLevel = value.requestedLevel
    @questionParts = value.questionParts
    @answerParts = value.answerParts
    setDisplayOnly = value.displayOnly?
    setPreview = value.preview?
end

#contains?(vocab) ⇒ Boolean

Returns true if the current problem contains the vocabulary passed in.

Returns:

  • (Boolean)


75
76
77
# File 'lib/jldrill/model/Problem.rb', line 75

def contains?(vocab)
    return @vocab.eql?(vocab)
end

#displayOnly?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/jldrill/model/Problem.rb', line 118

def displayOnly?
    return @displayOnly
end

#eql?(value) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
# File 'lib/jldrill/model/Problem.rb', line 36

def eql?(value)
    return @item == value.item &&
        @level == value.level &&
        @requestedLevel == value.requestedLevel &&
        @questionParts == value.questionParts &&
        @answerParts == value.answerParts &&
        displayOnly? == value.displayOnly? &&
        preview? == value.preview?
end

#evaluateAttribute(name) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/jldrill/model/Problem.rb', line 99

def evaluateAttribute(name)
    retVal = eval("@vocab." + name)
    if retVal.nil?
        retVal = ""
    end
    return retVal
end

#evaluateParts(parts) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/jldrill/model/Problem.rb', line 107

def evaluateParts(parts)
    retVal = ""
    parts.each do |part|
        value = evaluateAttribute(part)
        if !value.empty?
            retVal += value + "\n"
        end
    end
    retVal
end

#largeReading?Boolean

By default, don’t print the reading in large print

Returns:

  • (Boolean)


164
165
166
# File 'lib/jldrill/model/Problem.rb', line 164

def largeReading?
    return false
end

#nameObject

Override in the concrete classes



22
23
24
# File 'lib/jldrill/model/Problem.rb', line 22

def name
    return "Problem"
end

#parse(part) ⇒ Object



51
52
53
# File 'lib/jldrill/model/Problem.rb', line 51

def parse(part)
    return false
end

#preview?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/jldrill/model/Problem.rb', line 63

def preview?
    return @preview
end

#publishAnswer(target) ⇒ Object



154
155
156
# File 'lib/jldrill/model/Problem.rb', line 154

def publishAnswer(target)
    publishParts(@answerParts, target)
end

#publishParts(parts, target) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/jldrill/model/Problem.rb', line 122

def publishParts(parts, target)
    if preview?
        target.previewMode
    elsif displayOnly?
        target.displayOnlyMode
    else
        target.normalMode
    end
    parts.each do |part|
        value = evaluateAttribute(part)
        if !value.empty?
            if ((part == "reading") && (largeReading?))
                target.receive("kanji", value)
            else
                target.receive(part, value)
            end
        end
    end
end

#publishQuestion(target) ⇒ Object



150
151
152
# File 'lib/jldrill/model/Problem.rb', line 150

def publishQuestion(target)
    publishParts(@questionParts, target)
end

#questionObject



142
143
144
# File 'lib/jldrill/model/Problem.rb', line 142

def question
    evaluateParts(@questionParts)
end

#setDisplayOnly(bool) ⇒ Object



55
56
57
# File 'lib/jldrill/model/Problem.rb', line 55

def setDisplayOnly(bool)
    @displayOnly = bool
end

#setPreview(bool) ⇒ Object



59
60
61
# File 'lib/jldrill/model/Problem.rb', line 59

def setPreview(bool)
    @preview = bool
end

#statusObject

Return a string showing what bin this problem is from



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/jldrill/model/Problem.rb', line 80

def status
    retVal = "     "
    bin = @item.bin
    if bin < 4
        if bin == 0
            retVal += "New"
        else
            retVal += bin.to_s
        end
    else
        retVal += "+#{@item.itemStats.consecutive}"
        if @item.schedule.reviewed?
            retVal += ", #{@item.schedule.reviewedDate}"
        end
    end
    retVal += " --> #{@item.schedule.potentialScheduleInDays} days"
    return retVal
end

#to_sObject



46
47
48
49
# File 'lib/jldrill/model/Problem.rb', line 46

def to_s
    retVal = "/" + name
    return retVal
end

#valid?Boolean

Currently always valid.

Returns:

  • (Boolean)


159
160
161
# File 'lib/jldrill/model/Problem.rb', line 159

def valid?
    return true
end

#vocab=(vocab) ⇒ Object



67
68
69
70
71
# File 'lib/jldrill/model/Problem.rb', line 67

def vocab=(vocab)
    @vocab.assign(vocab)
    @item.setContents(vocab.contentString)
    @item.problemModified(self)
end