Class: LittleWeasel::DictionaryManager
- Inherits:
-
Object
- Object
- LittleWeasel::DictionaryManager
- Includes:
- Modules::DictionaryKeyValidatable
- Defined in:
- lib/LittleWeasel/dictionary_manager.rb
Overview
This class provides dictionary management functionality.
Instance Attribute Summary collapse
-
#dictionary_cache ⇒ Object
Returns the value of attribute dictionary_cache.
-
#dictionary_metadata ⇒ Object
Returns the value of attribute dictionary_metadata.
Instance Method Summary collapse
-
#create_dictionary_from_file(dictionary_key:, file:, word_filters: nil, word_preprocessors: nil) ⇒ Object
Adds a dictionary file source, creates the dictionary and returns the Dictionary object.
-
#create_dictionary_from_memory(dictionary_key:, dictionary_words:, word_filters: nil, word_preprocessors: nil) ⇒ Object
Adds a dictionary memory source, creates the dictionary and returns the Dictionary object.
- #dictionary_cache_service(dictionary_key:) ⇒ Object private
- #dictionary_creator_service(dictionary_key:, word_filters:, word_preprocessors:) ⇒ Object private
-
#dictionary_exist?(dictionary_key:) ⇒ Boolean
Returns true if a Dictionary object exists in the dictionary cache for the given dictionary_key.
-
#dictionary_for(dictionary_key:) ⇒ Object
Returns the Dictionary object associated with the dictionary_key.
- #dictionary_killer_service(dictionary_key:) ⇒ Object private
-
#init ⇒ Object
Resets the cache and metadata by clearing it out completely.
-
#initialize ⇒ DictionaryManager
constructor
A new instance of DictionaryManager.
-
#kill_dictionary(dictionary_key:) ⇒ Object
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.
Methods included from Modules::DictionaryKeyValidatable
#validate_dictionary_key, validate_dictionary_key
Constructor Details
#initialize ⇒ DictionaryManager
Returns a new instance of DictionaryManager.
14 15 16 17 18 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 14 def initialize self.dictionary_cache = {} self. = {} init end |
Instance Attribute Details
#dictionary_cache ⇒ Object
Returns the value of attribute dictionary_cache.
12 13 14 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 12 def dictionary_cache @dictionary_cache end |
#dictionary_metadata ⇒ Object
Returns the value of attribute dictionary_metadata.
12 13 14 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 12 def @dictionary_metadata end |
Instance Method Details
#create_dictionary_from_file(dictionary_key:, file:, word_filters: nil, word_preprocessors: nil) ⇒ Object
Adds a dictionary file source, creates the dictionary and returns the Dictionary object.
38 39 40 41 42 43 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 38 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) ⇒ Object
Adds a dictionary memory source, creates the dictionary and returns the Dictionary object.
47 48 49 50 51 52 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 47 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_cache_service(dictionary_key:) ⇒ Object (private)
76 77 78 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 76 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:) ⇒ Object (private)
80 81 82 83 84 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 80 def dictionary_creator_service(dictionary_key:, word_filters:, word_preprocessors:) Services::DictionaryCreatorService.new dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_metadata: , word_filters: word_filters, word_preprocessors: word_preprocessors end |
#dictionary_exist?(dictionary_key:) ⇒ Boolean
Returns true if a Dictionary object exists in the dictionary cache for the given dictionary_key.
22 23 24 25 26 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 22 def dictionary_exist?(dictionary_key:) validate_dictionary_key dictionary_key: dictionary_key dictionary_cache_service(dictionary_key: dictionary_key).dictionary_exist? end |
#dictionary_for(dictionary_key:) ⇒ Object
Returns the Dictionary object associated with the dictionary_key. If the Dictionary object does not exist in the dictionary cache, an error is raised.
30 31 32 33 34 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 30 def dictionary_for(dictionary_key:) validate_dictionary_key dictionary_key: dictionary_key dictionary_cache_service(dictionary_key: dictionary_key).dictionary_object! end |
#dictionary_killer_service(dictionary_key:) ⇒ Object (private)
86 87 88 89 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 86 def dictionary_killer_service(dictionary_key:) Services::DictionaryKillerService.new dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_metadata: end |
#init ⇒ Object
Resets the cache and metadata by clearing it out completely.
66 67 68 69 70 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 66 def init Services::DictionaryCacheService.init dictionary_cache: dictionary_cache Services::DictionaryMetadataService.init dictionary_metadata: self end |
#kill_dictionary(dictionary_key:) ⇒ Object
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.
58 59 60 61 62 63 |
# File 'lib/LittleWeasel/dictionary_manager.rb', line 58 def kill_dictionary(dictionary_key:) validate_dictionary_key dictionary_key: dictionary_key dictionary_killer_service(dictionary_key: dictionary_key).execute self end |