Class: Lita::Handlers::Gems

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

Instance Method Summary collapse

Instance Method Details

#info(response) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lita/handlers/gems.rb', line 24

def info(response)
  gem_name = response.args[0]
  return if gem_name == "q"
  data = ::Gems.info(gem_name)
  if data["version"]
    lines = ["version: #{data["version"]}", "rubygems: #{data["project_uri"]}"]
    lines << "homepage: #{data["homepage_uri"]}" if data["homepage_uri"]
    lines << "documentation: #{data["documentation_uri"]}" if data["documentation_uri"]
    lines << "source code: #{data["source_code_uri"]}" if data["source_code_uri"]
    response.reply lines.join("\n")
  else
    response.reply "This rubygem could not be found: #{gem_name}"
  end
end

#search(response) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/lita/handlers/gems.rb', line 10

def search(response)
  keyword = response.matches[0][0]
  results = ::Gems.search(keyword)
  if results.size == 0
    response.reply "Not found: #{keyword}"
  else
    response.reply "http://rubygems.org/search?query=#{URI::encode(keyword)}"
    response.reply results.map{ |d| "#{d["name"]}( #{d["version"]} ) : #{d["project_uri"]}" }.join("\n")
  end
end