Class: JDict::Dictionary
- Inherits:
-
Object
- Object
- JDict::Dictionary
- Defined in:
- lib/ruby-jdict/dictionary.rb
Instance Method Summary collapse
- #build_index! ⇒ Object
- #delete! ⇒ Object
- #dict_file ⇒ Object
-
#get_pos(pos) ⇒ String
Retrieves the definition of a part-of-speech from its abbreviation.
-
#initialize(path) ⇒ Dictionary
constructor
A new instance of Dictionary.
- #loaded? ⇒ Boolean
-
#search(query, opts = {}) ⇒ Array(Entry)
Search this dictionary’s index for the given string.
- #size ⇒ Object
Constructor Details
#initialize(path) ⇒ Dictionary
Returns a new instance of Dictionary.
3 4 5 6 7 8 |
# File 'lib/ruby-jdict/dictionary.rb', line 3 def initialize(path) @dictionary_path = File.join(path, self.dict_file) @entries = [] @index = DictIndex.new(@dictionary_path) end |
Instance Method Details
#build_index! ⇒ Object
14 15 16 |
# File 'lib/ruby-jdict/dictionary.rb', line 14 def build_index! @index.build_index! end |
#delete! ⇒ Object
45 46 47 |
# File 'lib/ruby-jdict/dictionary.rb', line 45 def delete! @index.delete! end |
#dict_file ⇒ Object
22 23 24 |
# File 'lib/ruby-jdict/dictionary.rb', line 22 def dict_file "JMDict" end |
#get_pos(pos) ⇒ String
Retrieves the definition of a part-of-speech from its abbreviation
41 42 43 |
# File 'lib/ruby-jdict/dictionary.rb', line 41 def get_pos(pos) @index.get_pos(pos) end |
#loaded? ⇒ Boolean
18 19 20 |
# File 'lib/ruby-jdict/dictionary.rb', line 18 def loaded? @index.built? end |
#search(query, opts = {}) ⇒ Array(Entry)
Search this dictionary’s index for the given string.
29 30 31 32 33 34 35 36 |
# File 'lib/ruby-jdict/dictionary.rb', line 29 def search(query, opts = {}) opts = opts.merge() results = [] return results if query.empty? results = @index.search(query, opts) end |
#size ⇒ Object
10 11 12 |
# File 'lib/ruby-jdict/dictionary.rb', line 10 def size @entries.size end |