Module: MethodNotMissing::MethodSearcher

Extended by:
MethodSearcher
Included in:
MethodSearcher
Defined in:
lib/method_not_missing/method_searcher.rb

Instance Method Summary collapse

Instance Method Details

#search_method(method_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/method_not_missing/method_searcher.rb', line 15

def search_method (method_name)
  puts "searching #{method_name}"
  @page ||= ::Capybara::Session.new(:poltergeist)
  @page.visit("http://www.google.co.uk/search")
  puts "Googling..."

  @page.fill_in "q", with: "\"def #{method_name}\" site:http://www.rubydoc.info/github"

  @page.click_button "Google Search"

  Enumerator.new do |y|
    links = @page.all("li.g h3").map do |h3|
      h3.find("a")[:href]
    end
    links.each do |url|
      @page.visit url
      html_codes = @page.body.scan(/<pre class="code">.*?<\/pre>/m)
      codes = html_codes.map do |html|
        CGI::unescapeHTML(html.gsub(/<.*?>/,""))
      end
      code = codes.grep(/def #{method_name}/).first
      y << code if code
    end
  end
end