Class: Synonymous::Sense

Inherits:
Object
  • Object
show all
Defined in:
lib/synonymous/sense.rb

Instance Method Summary collapse

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

#antonymsObject



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_antonymsObject



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

#numberObject



22
23
24
25
# File 'lib/synonymous/sense.rb', line 22

def number
  # https://dictionaryapi.com/products/json#sec-2.sn
  @data["sn"]
end


37
38
39
40
# File 'lib/synonymous/sense.rb', line 37

def related_words
  # https://dictionaryapi.com/products/json#sec-3.rellist
  @data.fetch("rel_list", []).flatten.map(&Word.method(:new))
end

#synonymous_phrasesObject



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

#synonymsObject



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_sObject



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