Sha256: 3f3a7496d07f46e09257e86bda43c008a47dc297172ba06fb1e4a0726a7365bb
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 KB
Contents
require 'Context/Context' require 'Context/Bridge' require 'Context/View' module JLDrill class ShowExamplesContext < Context::Context def initialize(viewBridge) super(viewBridge) end include JLDrill::Behaviour::SearchDictionary class ExampleView < Context::View attr_reader :exampleWindow def initialize(context) super(context) end # Destroy the window def destroy # Please define in the concrete class end # Update the examples in the UI def update(examples) # Please define in the concrete class end # This is a convenience function for the tests so that # they don't have to catch the close on the context def close @context.exit end end def createViews @mainView = @viewBridge.ExampleView.new(self) end def destroyViews @mainView.destroy if !@mainView.nil? @mainView = nil end def canDisplay?(parent) !parent.nil? && parent.class.public_method_defined?(:quiz) && !parent.quiz.nil? && parent.tanaka.loaded? end def findExamples(problem) examples = [] if !problem.nil? vocab = problem.item.to_o if !vocab.nil? examples = @parent.tanaka.search(vocab.kanji, vocab.reading) end end return examples end def enter(parent) if canDisplay?(parent) super(parent) @mainView.update(findExamples(@parent.quiz.currentProblem)) @parent.quiz.publisher.subscribe(self, "newProblem") end end def exit @parent.quiz.publisher.unsubscribe(self, "newProblem") super end def newProblemUpdated(problem) @mainView.update(findExamples(problem)) unless @mainView.nil? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jldrill-0.5.1.7 | lib/jldrill/contexts/ShowExamplesContext.rb |