Class: WhatIs::Dictionary
- Inherits:
-
Object
- Object
- WhatIs::Dictionary
- Defined in:
- lib/what_is/dictionary.rb
Constant Summary collapse
- BASE_URL =
"http://www.dictionaryapi.com"
Instance Method Summary collapse
- #define! ⇒ Object
-
#initialize(word) ⇒ Dictionary
constructor
A new instance of Dictionary.
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 end |