Class: Camdict::Word

Inherits:
Object
  • Object
show all
Defined in:
lib/camdict/word.rb

Overview

Get all definitions data about a word or phrase including IPAs, pronunciations, usage sentences, etc. from Camdict Client.

Instance Method Summary collapse

Constructor Details

#initialize(word, dictionary = nil) ⇒ Word

New a word or phrase, default dictionary is british.



10
11
12
13
14
15
# File 'lib/camdict/word.rb', line 10

def initialize(word, dictionary=nil)
  @word ||= word
  @dictionary = dictionary
  @raw_definitions = []   # each element is a hash
  @definitions = []       # each element is a Definition object
end

Instance Method Details

#definitionsObject

Get all definitions for this word from remote online dictionary



18
19
20
21
22
23
24
25
26
# File 'lib/camdict/word.rb', line 18

def definitions
  client = Camdict::Client.new(@dictionary)
  @raw_definitions = client.html_definition(@word)
  if found?
    @definitions = @raw_definitions.map { |r|
      Camdict::Definition.new(@word, r)
    }
  end
end

#found?Boolean Also known as: in?

Found in the diciontary? Return number of found entries

Returns:

  • (Boolean)


29
30
31
# File 'lib/camdict/word.rb', line 29

def found?
  @raw_definitions.size
end