Class: JLDrill::ShowExamplesContext

Inherits:
Context::Context show all
Includes:
Behaviour::SearchDictionary
Defined in:
lib/jldrill/contexts/ShowExamplesContext.rb

Defined Under Namespace

Classes: ExampleView

Instance Attribute Summary

Attributes inherited from Context::Context

#mainView, #parent, #viewBridge

Instance Method Summary collapse

Methods included from Behaviour::SearchDictionary

#dictionaryLoaded?, #findKanjiInDictionary, #kanjiInfo, #kanjiLoaded?, #search

Methods inherited from Context::Context

#addView, #isEntered?, #onExit, #peekAtView, #setupViews

Constructor Details

#initialize(viewBridge) ⇒ ShowExamplesContext

Returns a new instance of ShowExamplesContext.



10
11
12
13
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 10

def initialize(viewBridge)
	super(viewBridge)
          @examples = nil
end

Instance Method Details

#canDisplay?(parent) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 67

def canDisplay?(parent)
    !parent.nil? && parent.class.public_method_defined?(:quiz) &&
        !parent.quiz.nil? && parent.exampleDB.loaded?(parent.quiz.options)
end

#createViewsObject



58
59
60
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 58

def createViews
    @mainView = @viewBridge.ExampleView.new(self)
end

#destroyViewsObject



62
63
64
65
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 62

def destroyViews
    @mainView.destroy if !@mainView.nil?
    @mainView = nil
end

#enter(parent) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 85

def enter(parent)
    if canDisplay?(parent)
  		    super(parent)
  		    @mainView.update(findExamples(@parent.quiz.currentProblem))
  		    @parent.quiz.publisher.subscribe(self, "newProblem")
  		    @parent.quiz.publisher.subscribe(self, "load")
              @parent.longEventPublisher.subscribe(self, "startLongEvent")
              @parent.longEventPublisher.subscribe(self, "stopLongEvent")
              newProblemUpdated(@parent.quiz.currentProblem)
  		else
              print "Can't Display\n"
          end
end

#exitObject



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

def exit
    @parent.quiz.publisher.unsubscribe(self, "newProblem")
    @parent.quiz.publisher.unsubscribe(self, "load")
          @parent.longEventPublisher.unsubscribe(self, "startLongEvent")
          @parent.longEventPublisher.unsubscribe(self, "stopLongEvent")
    super
end

#findExamples(problem) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 72

def findExamples(problem)
	examples = []
	if !problem.nil?
		vocab = problem.item.to_o
		if !vocab.nil?
			examples = @parent.exampleDB.search(vocab.kanji, 
                                                      vocab.reading,
                                                      @parent.quiz.options)
		end
	end
	return examples
end

#loadUpdated(quiz) ⇒ Object



118
119
120
121
122
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 118

def loadUpdated(quiz)
    # The language might have changed, so we might need to
    # load a new index file
    @parent.loadExamples
end

#newProblemUpdated(problem) ⇒ Object



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

def newProblemUpdated(problem)
          if !@mainView.nil? && !problem.nil?
              @examples = findExamples(problem)
              if (problem.name.eql?("MeaningProblem"))
                  @mainView.updateNativeOnly(@examples)
              else
                  @mainView.updateTargetOnly(@examples)
              end
          end
end

#showAnswerObject



132
133
134
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 132

def showAnswer()
    @mainView.update(@examples) unless @mainView.nil?
end

#startLongEventUpdated(source) ⇒ Object



124
125
126
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 124

def startLongEventUpdated(source)
    @mainView.showBusy(true)
end

#stopLongEventUpdated(source) ⇒ Object



128
129
130
# File 'lib/jldrill/contexts/ShowExamplesContext.rb', line 128

def stopLongEventUpdated(source)
    @mainView.showBusy(false)
end