Class: Lita::Handlers::GoogleRanking

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/google-ranking.rb

Instance Method Summary collapse

Instance Method Details

#gr(response) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lita/handlers/google-ranking.rb', line 17

def gr(response)
  # raise response.matches.inspect
  domain = response.matches.first.first
  keyword = response.matches.first[1]
  results = Google::Search::Web.new(:query => keyword, :safety_level => :off, :gl => config(:gl), :lr => config(:lr), :cr => config(:cr), :size => :large)
  rank = nil
  results.each do |res|
    if res.uri.index(domain)
      rank = res.index + 1
      break
    end
  end
  if rank
    response.reply "\"#{keyword}\" ranking of #{domain} is #{rank}"
  else
    response.reply "\"#{keyword}\" ranking of #{domain} doesn't appear in search restults"
  end
end