Class: Chen::Google
- Inherits:
-
Google
- Object
- Chen::Google
- Defined in:
- lib/chen.rb
Class Method Summary collapse
- .query(str, page_number = 1, size = 8) ⇒ Object
- .query_to_json(str, page_number = 1, size = 10) ⇒ Object
Instance Method Summary collapse
-
#to_results ⇒ Object
copied mostly from the “show” method.
Class Method Details
Instance Method Details
#to_results ⇒ Object
copied mostly from the “show” method
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/chen.rb', line 52 def to_results info = request :q => @query, :rsz => @opts[:size], :start => ((@opts[:page] - 1) * @opts[:size]) results = info[:results] query_strings = info[:query_strings] coder = HTMLEntities.new current_page = results['responseData']['cursor']['currentPageIndex']+1 max_result = query_strings[:start] + query_strings[:rsz] estimated_results = results['responseData']['cursor']['resultCount'] result_array = results['responseData']['results'] datas = [] result_array.each_with_index do |result, i| new_data = Chen::SearchResult.new new_data.tap do |d| d.title = result["titleNoFormatting"] d.url = result["url"] d.desc = result["content"].squeeze(" ") d.number = (i + query_strings[:start] + 1) d.estimated = estimated_results end datas << new_data end return datas end |