Class: JDict::Dictionary
- Inherits:
-
Object
- Object
- JDict::Dictionary
- Defined in:
- lib/dictionary.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#entries_cache ⇒ Object
readonly
Returns the value of attribute entries_cache.
-
#lazy_index_loading ⇒ Object
readonly
Returns the value of attribute lazy_index_loading.
Instance Method Summary collapse
-
#get_pos(pos) ⇒ String
Retrieves the definition of a part-of-speech from its abbreviation.
-
#initialize(index_path = JDict.configuration.index_path, dictionary_path = nil, lazy_index_loading = JDict.configuration.lazy_index_loading) ⇒ Dictionary
constructor
A new instance of Dictionary.
- #loaded? ⇒ Boolean
-
#search(query) ⇒ Array(Entry)
Search this dictionary’s index for the given string.
- #size ⇒ Object
Constructor Details
#initialize(index_path = JDict.configuration.index_path, dictionary_path = nil, lazy_index_loading = JDict.configuration.lazy_index_loading) ⇒ Dictionary
Returns a new instance of Dictionary.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dictionary.rb', line 8 def initialize(index_path = JDict.configuration.index_path, dictionary_path = nil, lazy_index_loading = JDict.configuration.lazy_index_loading) path_specified = dictionary_path.nil? ? false : true if path_specified and not File.exists? dictionary_path raise "Dictionary not found at path #{dictionary_path}" end #store some args for future reference @dictionary_path = dictionary_path @lazy_index_loading = lazy_index_loading @entries = [] @entries_cache = [] #instantiate and load the full-text search index @index = DictIndex.new(index_path, dictionary_path, lazy_index_loading) end |
Instance Attribute Details
#entries_cache ⇒ Object (readonly)
Returns the value of attribute entries_cache.
6 7 8 |
# File 'lib/dictionary.rb', line 6 def entries_cache @entries_cache end |
#lazy_index_loading ⇒ Object (readonly)
Returns the value of attribute lazy_index_loading.
6 7 8 |
# File 'lib/dictionary.rb', line 6 def lazy_index_loading @lazy_index_loading end |
Instance Method Details
#get_pos(pos) ⇒ String
Retrieves the definition of a part-of-speech from its abbreviation
48 49 50 |
# File 'lib/dictionary.rb', line 48 def get_pos(pos) @index.get_pos(pos) end |
#loaded? ⇒ Boolean
29 30 31 |
# File 'lib/dictionary.rb', line 29 def loaded? @index.built? end |
#search(query) ⇒ Array(Entry)
Search this dictionary’s index for the given string.
36 37 38 39 40 41 42 43 |
# File 'lib/dictionary.rb', line 36 def search(query) results = [] return results if query.empty? load_index if lazy_index_loading and not loaded? results = @index.search(query) end |
#size ⇒ Object
25 26 27 |
# File 'lib/dictionary.rb', line 25 def size @entries.size end |