Class: JDict::Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-jdict/dictionary.rb

Instance Method Summary collapse

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_fileObject



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

Parameters:

  • pos (String)

    the abbreviation for the part-of-speech

Returns:

  • (String)

    the full description of the part-of-speech



41
42
43
# File 'lib/ruby-jdict/dictionary.rb', line 41

def get_pos(pos)
  @index.get_pos(pos)
end

#loaded?Boolean

Returns:

  • (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.

Parameters:

  • query (String)

    the search query

Returns:

  • (Array(Entry))

    the results of the search



29
30
31
32
33
34
35
36
# File 'lib/ruby-jdict/dictionary.rb', line 29

def search(query, opts = {})
  opts = opts.merge(default_search_options)

  results = []
  return results if query.empty?

  results = @index.search(query, opts)
end

#sizeObject



10
11
12
# File 'lib/ruby-jdict/dictionary.rb', line 10

def size
  @entries.size
end