Class: SiteSearch::GoogleSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/site_search/google_search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_engine, query, options = {}) ⇒ GoogleSearch

Returns a new instance of GoogleSearch.

Raises:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/site_search/google_search.rb', line 10

def initialize(search_engine, query, options={})
  raise NoResults.new if query.blank?
  @query = escape_html(query).gsub(" ", '+')
  @results = []
  doc = get_document(set_uri(options, search_engine.to_s))
  @raw = doc.body
  case options[:alt]
    when 'atom' then parse_atom(doc)
    else parse_json(doc)
  end
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



8
9
10
# File 'lib/site_search/google_search.rb', line 8

def raw
  @raw
end

#resultsObject (readonly)

Returns the value of attribute results.



8
9
10
# File 'lib/site_search/google_search.rb', line 8

def results
  @results
end

#start_indexObject (readonly)

Returns the value of attribute start_index.



8
9
10
# File 'lib/site_search/google_search.rb', line 8

def start_index
  @start_index
end

#totalObject (readonly)

Returns the value of attribute total.



8
9
10
# File 'lib/site_search/google_search.rb', line 8

def total
  @total
end