Module: UrbanDictionary
- Defined in:
- lib/urbandict.rb
Defined Under Namespace
Classes: UrbanDictError
Constant Summary collapse
- URL =
'https://api.urbandictionary.com/v0/define'
Class Method Summary collapse
-
.define(word) ⇒ Array<Slang>
Gets the definitions for the word.
Instance Method Summary collapse
-
#define(word) ⇒ Array<Slang>
private
Gets the definitions for the word.
Class Method Details
.define(word) ⇒ Array<Slang>
Gets the definitions for the word.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/urbandict.rb', line 14 def define(word) params = { term: word } @client = HTTPClient.new if @client.nil? response = JSON.parse(@client.get(URI.parse(URL), params).body) if response.key?('error') raise UrbanDictError.new end ret = [] response['list'].each do |hash| ret << Slang.new(hash) end ret end |
Instance Method Details
#define(word) ⇒ Array<Slang> (private)
Gets the definitions for the word.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/urbandict.rb', line 14 def define(word) params = { term: word } @client = HTTPClient.new if @client.nil? response = JSON.parse(@client.get(URI.parse(URL), params).body) if response.key?('error') raise UrbanDictError.new end ret = [] response['list'].each do |hash| ret << Slang.new(hash) end ret end |