Class: Synonymous::Sense
- Inherits:
-
Object
- Object
- Synonymous::Sense
- Defined in:
- lib/synonymous/sense.rb
Instance Method Summary collapse
- #antonyms ⇒ Object
-
#initialize(data) ⇒ Sense
constructor
A new instance of Sense.
- #near_antonyms ⇒ Object
- #number ⇒ Object
- #related_words ⇒ Object
- #synonymous_phrases ⇒ Object
- #synonyms ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Sense
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/synonymous/sense.rb', line 5 def initialize(data) if data.length > 1 pp data raise Synonymous::Error, "Sense Sequence has more than one element" end unless data[0][0] == "sense" pp data[0] raise Synonymous::Error, "Sense didn't start with keyword 'sense'" end unless data[0].length == 2 pp data[0] raise Synonymous::Error, "Sense has more than two entries" end @data = data[0][1] end |
Instance Method Details
#antonyms ⇒ Object
47 48 49 50 |
# File 'lib/synonymous/sense.rb', line 47 def antonyms # https://dictionaryapi.com/products/json#sec-3.antlist @data.fetch("ant_list", []).flatten.map(&Word.method(:new)) end |
#near_antonyms ⇒ Object
52 53 54 55 |
# File 'lib/synonymous/sense.rb', line 52 def near_antonyms # https://dictionaryapi.com/products/json#sec-3.nearlist @data.fetch("near_list", []).flatten.map(&Word.method(:new)) end |
#number ⇒ Object
22 23 24 25 |
# File 'lib/synonymous/sense.rb', line 22 def number # https://dictionaryapi.com/products/json#sec-2.sn @data["sn"] end |
#related_words ⇒ Object
37 38 39 40 |
# File 'lib/synonymous/sense.rb', line 37 def # https://dictionaryapi.com/products/json#sec-3.rellist @data.fetch("rel_list", []).flatten.map(&Word.method(:new)) end |
#synonymous_phrases ⇒ Object
42 43 44 45 |
# File 'lib/synonymous/sense.rb', line 42 def synonymous_phrases # https://dictionaryapi.com/products/json#sec-3.phraselist @data.fetch("phrase_list", []).flatten.map(&Word.method(:new)) end |
#synonyms ⇒ Object
32 33 34 35 |
# File 'lib/synonymous/sense.rb', line 32 def synonyms # https://dictionaryapi.com/products/json#sec-3.synlist @data.fetch("syn_list", []).flatten.map(&Word.method(:new)) end |
#to_s ⇒ Object
27 28 29 30 |
# File 'lib/synonymous/sense.rb', line 27 def to_s # https://dictionaryapi.com/products/json#sec-2.dt @data.fetch("dt").to_h.fetch("text").strip end |