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

Class Method Details

.define(word) ⇒ Array<Slang>

Gets the definitions for the word.

Parameters:

  • word (String)

    The word to define.

Returns:

Raises:



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