Class: Camdict::Word
- Inherits:
-
Object
- Object
- Camdict::Word
- 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
-
#definitions ⇒ Object
Get all definitions for this word from remote online dictionary.
-
#found? ⇒ Boolean
(also: #in?)
Found in the diciontary? Return number of found entries.
-
#initialize(word, dictionary = nil) ⇒ Word
constructor
New a
word
or phrase, defaultdictionary
is british.
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
#definitions ⇒ Object
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
29 30 31 |
# File 'lib/camdict/word.rb', line 29 def found? @raw_definitions.size end |