lib/gsearch-parser.rb in gsearch-parser-0.3.4 vs lib/gsearch-parser.rb in gsearch-parser-0.3.5
- old
+ new
@@ -6,29 +6,38 @@
#
module GSearchParser
# Entry method for performing a web search
def GSearchParser.webSearch(query)
- webSearch = GoogleWebSearch.new(query)
+ webSearch = GoogleWebSearch.new(query, 'QUERY')
end
+ # Allows directly specifing the URI of the page to parse
+ def GSearchParser.parseSearchPage(uri)
+ webSearch = GoogleWebSearch.new(uri, 'URI')
+ end
+
end
#
# Google Web Search class
#
class GoogleWebSearch
attr_accessor :results, :nextURI
@currentPage
# Class initializer
- def initialize(query)
+ def initialize(arg1, flag)
# Initialize variables
@results = Array.new
- # Update the results list: (Fetch, Store, and Parse)
- updateResults("http://google.com/search?sourceid=chrome&q=#{query}")
+ case flag
+ when 'QUERY'
+ updateResults("http://google.com/search?sourceid=chrome&q=#{arg1}")
+ when 'URI'
+ updateResults(arg1)
+ end
# Update next URI
updateNextURI
end
@@ -43,10 +52,10 @@
# Update the WebSearch results array by performing a Fetch, Store, Parse routine
def updateResults(url)
# Fetch
searchPage = fetchPage(url)
-
+puts url
# Store
@currentPage = searchPage
# Parse
parseCurrentPage