Class: Vocabulary::Word
- Inherits:
-
Object
- Object
- Vocabulary::Word
- Defined in:
- lib/vocabulary.rb
Instance Attribute Summary collapse
-
#meanings ⇒ Object
Returns the value of attribute meanings.
-
#part_of_speech ⇒ Object
Returns the value of attribute part_of_speech.
Instance Method Summary collapse
-
#initialize(summary, source_lang) ⇒ Word
constructor
A new instance of Word.
Constructor Details
#initialize(summary, source_lang) ⇒ Word
Returns a new instance of Word.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vocabulary.rb', line 16 def initialize summary, source_lang begin @meanings = [] if source_lang == :en @part_of_speech = summary["primaries"][0]["terms"][0]["labels"][0]["text"] collection = summary["primaries"][0]["entries"] else @part_of_speech = summary["primaries"][0]["entries"][0]["labels"][0]["text"] collection = summary["primaries"][0]["entries"][0]["entries"] end collection.each do |meaning| @meanings << meaning["terms"][0]["text"] end rescue raise Vocabulary::LookUpError.new(summary) end end |
Instance Attribute Details
#meanings ⇒ Object
Returns the value of attribute meanings.
14 15 16 |
# File 'lib/vocabulary.rb', line 14 def meanings @meanings end |
#part_of_speech ⇒ Object
Returns the value of attribute part_of_speech.
14 15 16 |
# File 'lib/vocabulary.rb', line 14 def part_of_speech @part_of_speech end |