Class: Lita::Handlers::UrbanDictionary

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/urban_dictionary.rb

Overview

Looks up words on Urban Dictionary.

Instance Method Summary collapse

Instance Method Details

#define(response) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lita/handlers/urban_dictionary.rb', line 16

def define(response)
  term = response.matches[0][0]
  word, definition, example = fetch_definition(term)
  if word
    lines = "#{word}: #{definition}".split("\n")
    lines << "Example: #{example}" if example
    message = message_from_lines(lines, term)
    response.reply(message)
  else
    response.reply("No definition found for #{term}.")
  end
end