Class: Lita::Handlers::Wtf

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

Constant Summary collapse

SOURCE_NAMES =
{
  'merriam' => 'Merriam-Webster Collegiate Dictionary',
  'urbandictionary' => 'UrbanDictionary'
}.freeze

Instance Method Summary collapse

Instance Method Details

#define(response) ⇒ Object



43
44
45
46
47
48
# File 'lib/lita/handlers/wtf.rb', line 43

def define(response)
  term = response.match_data['term']
  info = response.match_data['definition']
  write(term, info, response.user.id)
  response.reply(format_definition(term, definition(term)))
end

#lookup(response) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lita/handlers/wtf.rb', line 30

def lookup(response)
  term = response.match_data['term']
  return response.reply(format_definition(term, definition(term))) if known?(term)

  definition, source_name = alternate_definition(term)
  return response.reply(t('wtf.seealso',
                          term: term,
                          definition: definition,
                          source: SOURCE_NAMES[source_name])) if definition

  response.reply(t('wtf.unknown', term: term))
end