Class: FreeDictionaryApi::Word

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Word

Returns a new instance of Word.



5
6
7
8
9
10
11
# File 'lib/free_dictionary_api/word.rb', line 5

def initialize(data)
  @word = data['word']
  @phonetic = data['phonetic']
  @phonetics = data['phonetics']
  @origin = data['origin']
  @meanings = data['meanings']
end

Instance Attribute Details

#meaningsObject (readonly)

Returns the value of attribute meanings.



3
4
5
# File 'lib/free_dictionary_api/word.rb', line 3

def meanings
  @meanings
end

#originObject (readonly)

Returns the value of attribute origin.



3
4
5
# File 'lib/free_dictionary_api/word.rb', line 3

def origin
  @origin
end

#phoneticObject (readonly)

Returns the value of attribute phonetic.



3
4
5
# File 'lib/free_dictionary_api/word.rb', line 3

def phonetic
  @phonetic
end

#phoneticsObject (readonly)

Returns the value of attribute phonetics.



3
4
5
# File 'lib/free_dictionary_api/word.rb', line 3

def phonetics
  @phonetics
end

#wordObject (readonly)

Returns the value of attribute word.



3
4
5
# File 'lib/free_dictionary_api/word.rb', line 3

def word
  @word
end

Instance Method Details

#antonymsObject



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

def antonyms
  definitions.flat_map { |definition| definition['antonyms'] }.compact
end

#definitionsObject



13
14
15
# File 'lib/free_dictionary_api/word.rb', line 13

def definitions
  meanings.flat_map { |meaning| meaning['definitions'] }
end

#examplesObject



21
22
23
# File 'lib/free_dictionary_api/word.rb', line 21

def examples
  definitions.map { |definition| definition['example'] }.compact
end

#parts_of_speechObject



17
18
19
# File 'lib/free_dictionary_api/word.rb', line 17

def parts_of_speech
  meanings.map { |meaning| meaning['partOfSpeech'] }.uniq
end

#synonymsObject



25
26
27
# File 'lib/free_dictionary_api/word.rb', line 25

def synonyms
  definitions.flat_map { |definition| definition['synonyms'] }.compact
end