Class: WhatIs::Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/what_is/dictionary.rb

Constant Summary collapse

BASE_URL =
"http://www.dictionaryapi.com"

Instance Method Summary collapse

Constructor Details

#initialize(word) ⇒ Dictionary

Returns a new instance of Dictionary.



9
10
11
# File 'lib/what_is/dictionary.rb', line 9

def initialize(word)
  @word = word
end

Instance Method Details

#define!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/what_is/dictionary.rb', line 13

def define!
  raise WhatIs::NoApiKeyException unless api_key

  uri = URI.parse(api_endpoint)
  response = Net::HTTP.get_response(uri)
  doc = Nokogiri::XML(response.body)


  doc.xpath("//dt").first.text

rescue NoApiKeyException => e
  no_api_key_exception_message
end