Class: GoogleSiteSearch::Search
- Inherits:
-
Object
- Object
- GoogleSiteSearch::Search
- Defined in:
- lib/google-site-search/search.rb
Overview
Search is responsible for parsing the returned xml from google’s API.
XML parsing is done using LibXML Ruby
Instance Attribute Summary collapse
-
#estimated_results_total ⇒ Object
readonly
Pulled from the XML as the estimated total number of results.
-
#next_results_url ⇒ Object
readonly
Relative URL to get the next set of results (if any).
-
#previous_results_url ⇒ Object
readonly
Relative URL to get the previous set of results (if any).
-
#result_class ⇒ Object
readonly
Class supplied which is responsible for parsing each individual result from the API XML.
-
#results ⇒ Object
readonly
Array of result_class objects.
-
#search_query ⇒ Object
readonly
The full search term + filters query google interpreted from the url supplied.
-
#spelling ⇒ Object
readonly
Spelling suggestion in HTML format.
-
#spelling_q ⇒ Object
readonly
Spelling suggestion URL escaped.
-
#url ⇒ Object
readonly
Goolge Site Search API url.
-
#xml ⇒ Object
readonly
String of the xml returned by Google.
Instance Method Summary collapse
-
#initialize(url, result_class) ⇒ Search
constructor
Attributes.
-
#query ⇒ Object
Query’s Google API, stores the xml and parses values into itself.
Constructor Details
#initialize(url, result_class) ⇒ Search
Attributes
-
url- Expects a fully qualified url to Googles search API (can be a string or from an objects to_s method). -
reulst_class- A class that’s initialize method is expected to handle the parsing of an individual result entry.
41 42 43 44 45 |
# File 'lib/google-site-search/search.rb', line 41 def initialize url, result_class @url = url.to_s @results = Array.new @result_class = result_class end |
Instance Attribute Details
#estimated_results_total ⇒ Object (readonly)
Pulled from the XML as the estimated total number of results. Note Google themselves say this may not be accurate.
20 21 22 |
# File 'lib/google-site-search/search.rb', line 20 def estimated_results_total @estimated_results_total end |
#next_results_url ⇒ Object (readonly)
Relative URL to get the next set of results (if any).
22 23 24 |
# File 'lib/google-site-search/search.rb', line 22 def next_results_url @next_results_url end |
#previous_results_url ⇒ Object (readonly)
Relative URL to get the previous set of results (if any).
24 25 26 |
# File 'lib/google-site-search/search.rb', line 24 def previous_results_url @previous_results_url end |
#result_class ⇒ Object (readonly)
Class supplied which is responsible for parsing each individual result from the API XML.
29 30 31 |
# File 'lib/google-site-search/search.rb', line 29 def result_class @result_class end |
#results ⇒ Object (readonly)
Array of result_class objects.
13 14 15 |
# File 'lib/google-site-search/search.rb', line 13 def results @results end |
#search_query ⇒ Object (readonly)
The full search term + filters query google interpreted from the url supplied.
32 33 34 |
# File 'lib/google-site-search/search.rb', line 32 def search_query @search_query end |
#spelling ⇒ Object (readonly)
Spelling suggestion in HTML format.
15 16 17 |
# File 'lib/google-site-search/search.rb', line 15 def spelling @spelling end |
#spelling_q ⇒ Object (readonly)
Spelling suggestion URL escaped.
17 18 19 |
# File 'lib/google-site-search/search.rb', line 17 def spelling_q @spelling_q end |
#url ⇒ Object (readonly)
Goolge Site Search API url.
11 12 13 |
# File 'lib/google-site-search/search.rb', line 11 def url @url end |
#xml ⇒ Object (readonly)
String of the xml returned by Google.
26 27 28 |
# File 'lib/google-site-search/search.rb', line 26 def xml @xml end |
Instance Method Details
#query ⇒ Object
Query’s Google API, stores the xml and parses values into itself.
57 58 59 60 61 |
# File 'lib/google-site-search/search.rb', line 57 def query @xml = GoogleSiteSearch::request_xml(url) parse_xml unless @xml.nil? self end |