Skip to content

Instantly share code, notes, and snippets.

@omarqureshi
Last active December 31, 2015 10:49
Show Gist options
  • Save omarqureshi/7975136 to your computer and use it in GitHub Desktop.
Save omarqureshi/7975136 to your computer and use it in GitHub Desktop.
def calculate_rank_for(target, query)
rank = nil
each_google_result_page(query, 6) do |page, page_index|
each_google_result(page) do |result, result_index|
return ((page_index * 10) + result_index) if result.text.include?(target)
end
end
end
def show_rank_for(target, query)
rank = calculate_rank_for(target, query)
puts "#{target} is ranked #{rank} for search '#{query}'"
end
show_rank_for("avdi.org", "nonesuch")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment