Class: FreeDictionaryApi::Word
- Inherits:
-
Object
- Object
- FreeDictionaryApi::Word
- Defined in:
- lib/free_dictionary_api/word.rb
Instance Attribute Summary collapse
-
#meanings ⇒ Object
readonly
Returns the value of attribute meanings.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#phonetic ⇒ Object
readonly
Returns the value of attribute phonetic.
-
#phonetics ⇒ Object
readonly
Returns the value of attribute phonetics.
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Instance Method Summary collapse
- #antonyms ⇒ Object
- #definitions ⇒ Object
- #examples ⇒ Object
-
#initialize(data) ⇒ Word
constructor
A new instance of Word.
- #parts_of_speech ⇒ Object
- #synonyms ⇒ Object
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
#meanings ⇒ Object (readonly)
Returns the value of attribute meanings.
3 4 5 |
# File 'lib/free_dictionary_api/word.rb', line 3 def meanings @meanings end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
3 4 5 |
# File 'lib/free_dictionary_api/word.rb', line 3 def origin @origin end |
#phonetic ⇒ Object (readonly)
Returns the value of attribute phonetic.
3 4 5 |
# File 'lib/free_dictionary_api/word.rb', line 3 def phonetic @phonetic end |
#phonetics ⇒ Object (readonly)
Returns the value of attribute phonetics.
3 4 5 |
# File 'lib/free_dictionary_api/word.rb', line 3 def phonetics @phonetics end |
#word ⇒ Object (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
#antonyms ⇒ Object
29 30 31 |
# File 'lib/free_dictionary_api/word.rb', line 29 def antonyms definitions.flat_map { |definition| definition['antonyms'] }.compact end |
#definitions ⇒ Object
13 14 15 |
# File 'lib/free_dictionary_api/word.rb', line 13 def definitions meanings.flat_map { |meaning| meaning['definitions'] } end |
#examples ⇒ Object
21 22 23 |
# File 'lib/free_dictionary_api/word.rb', line 21 def examples definitions.map { |definition| definition['example'] }.compact end |
#parts_of_speech ⇒ Object
17 18 19 |
# File 'lib/free_dictionary_api/word.rb', line 17 def parts_of_speech meanings.map { |meaning| meaning['partOfSpeech'] }.uniq end |
#synonyms ⇒ Object
25 26 27 |
# File 'lib/free_dictionary_api/word.rb', line 25 def synonyms definitions.flat_map { |definition| definition['synonyms'] }.compact end |