Sha256: 49e96bfe61cf91de3e24d92a9f286a9da31dc501190347d2b9636a1f81b19866

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require 'Context/Context'
require 'Context/Bridge'
require 'jldrill/model/Config'
require 'jldrill/contexts/LoadFileContext'

module JLDrill

    # Load the reference dictionary
	class LoadReferenceContext < Context::Context
		
		def initialize(viewBridge)
			super(viewBridge)
            @loadFileContext = LoadFileContext.new(@viewBridge)
		end

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

        def destroyViews
            @mainView = nil
        end

        def dictionaryName(options)
            if !options.nil? && !options.dictionary.nil?
                return options.dictionary
            else
                return Config::DICTIONARY_NAME
            end
        end

        # Returns the filename of the dictionary including the path
        def getFilename(options)
            return File.expand_path(dictionaryName(options), 
                                    Config::DICTIONARY_DIR)
        end

        def getDeinflectionFilename
            return File.expand_path(Config::DEINFLECTION_NAME,
                                    Config::DEINFLECTION_DIR)
        end

        def loadDeinflection(deinflect, filename)
            @loadFileContext.onExit do
                exitLoadReferenceContext
            end
            @loadFileContext.enter(self, deinflect, filename)
        end

        def loadReference(reference, deinflect, filename)
            @loadFileContext.onExit do
               loadDeinflection(deinflect, getDeinflectionFilename) 
            end
            @loadFileContext.enter(self, reference, filename)
        end

        def exitLoadReferenceContext
            self.exit
        end

        def enter(parent, reference, deinflect, options)
            super(parent)
            loadReference(reference, deinflect, getFilename(options))
        end

    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jldrill-0.5.1.7 lib/jldrill/contexts/LoadReferenceContext.rb