Sha256: 60dc007a84605202330005a39fc04440d54b6f70ece6eabb32c95f16dc0976b7

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require "gss/version"
require "rubygems"
require "nokogiri"
require "open-uri"
require "certified"

module Gss
    attr_accessor :site_name, :search_for, :gss_url, :noko

    # Initializes Gss with a site to search and 
    # things to search for. Returns top result, and top results.
    #
    # @param site_name [String] site to be searched.
    # @param search_for [String] string to search for.
    # @return [Array] contains Hash objects for the top result, and top results.
    def self.return_results(site_name, search_for)
        @site_name = site_name
        @search_for = search_for.gsub(" ", "+")
        @gss_url = "https://www.google.com/search?q=site%3A#{@site_name}+#{@search_for}"
        @noko = Nokogiri::HTML(open(@gss_url))
        results = top_results()
        
        return [results[0], results]
    end

    # This will return as array of Hash objects containing information about
    # the top links.
    #
    # @return results [Array] array of hash objects that contain info about top links
    def self.top_results()
        results = []

        @noko.css("li.g").each do |link|
            # puts link
            result = Hash.new
            result[:name] = link.css("h3")[0].text
            result[:url] = "http://google.com" + link.css("h3 a")[0]["href"]
            result[:description] = link.css("span.st")[0].text

            results << result
        end

        return results
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gss-0.0.7 lib/gss.rb