class LittleWeasel::DictionaryManager
This class provides dictionary management functionality.
Attributes
dictionary_cache[RW]
dictionary_metadata[RW]
Public Class Methods
new()
click to toggle source
# File lib/LittleWeasel/dictionary_manager.rb, line 14 def initialize self.dictionary_cache = {} self.dictionary_metadata = {} init end
Public Instance Methods
create_dictionary_from_file(dictionary_key:, file:, word_filters: nil, word_preprocessors: nil)
click to toggle source
Adds a dictionary file source, creates the dictionary and returns the Dictionary
object.
# File lib/LittleWeasel/dictionary_manager.rb, line 32 def create_dictionary_from_file(dictionary_key:, file:, word_filters: nil, word_preprocessors: nil) validate_dictionary_key dictionary_key: dictionary_key dictionary_creator_service(dictionary_key: dictionary_key, word_filters: word_filters, word_preprocessors: word_preprocessors).from_file_source file: file end
create_dictionary_from_memory(dictionary_key:, dictionary_words:, word_filters: nil, word_preprocessors: nil)
click to toggle source
Adds a dictionary memory source, creates the dictionary and returns the Dictionary
object.
# File lib/LittleWeasel/dictionary_manager.rb, line 41 def create_dictionary_from_memory(dictionary_key:, dictionary_words:, word_filters: nil, word_preprocessors: nil) validate_dictionary_key dictionary_key: dictionary_key dictionary_creator_service(dictionary_key: dictionary_key, word_filters: word_filters, word_preprocessors: word_preprocessors).from_memory_source dictionary_words: dictionary_words end
dictionary_for(dictionary_key:)
click to toggle source
# File lib/LittleWeasel/dictionary_manager.rb, line 20 def dictionary_for(dictionary_key:) validate_dictionary_key dictionary_key: dictionary_key unless dictionary_cache_service(dictionary_key: dictionary_key).dictionary_exists? # TODO: Raise an error or let the service handle it? end dictionary_cache_service(dictionary_key: dictionary_key).dictionary_object! end
init()
click to toggle source
Resets the cache and metadata by clearing it out completely.
# File lib/LittleWeasel/dictionary_manager.rb, line 60 def init Services::DictionaryCacheService.init dictionary_cache: dictionary_cache Services::DictionaryMetadataService.init dictionary_metadata: dictionary_metadata self end
kill_dictionary(dictionary_key:)
click to toggle source
Removes any and all traces of the dictionary associated with the dictionary key from the dictionary cache - the Dictionary
object, file reference and any metadata associated with the dictionary are completely removed from the dictionary cache.
# File lib/LittleWeasel/dictionary_manager.rb, line 52 def kill_dictionary(dictionary_key:) validate_dictionary_key dictionary_key: dictionary_key dictionary_killer_service(dictionary_key: dictionary_key).execute self end
Private Instance Methods
dictionary_cache_service(dictionary_key:)
click to toggle source
# File lib/LittleWeasel/dictionary_manager.rb, line 70 def dictionary_cache_service(dictionary_key:) Services::DictionaryCacheService.new dictionary_key: dictionary_key, dictionary_cache: dictionary_cache end
dictionary_creator_service(dictionary_key:, word_filters:, word_preprocessors:)
click to toggle source
# File lib/LittleWeasel/dictionary_manager.rb, line 74 def dictionary_creator_service(dictionary_key:, word_filters:, word_preprocessors:) Services::DictionaryCreatorService.new dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_metadata: dictionary_metadata, word_filters: word_filters, word_preprocessors: word_preprocessors end
dictionary_killer_service(dictionary_key:)
click to toggle source
# File lib/LittleWeasel/dictionary_manager.rb, line 80 def dictionary_killer_service(dictionary_key:) Services::DictionaryKillerService.new dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_metadata: dictionary_metadata end