Class: Chen::Google
- Inherits:
-
Google
- Object
- Chen::Google
- Defined in:
- lib/chen.rb
Class Method Summary collapse
- .query(str, page_number = 1, size = 10) ⇒ 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
.query(str, page_number = 1, size = 10) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chen.rb', line 31 def query(str, page_number = 1, size = 10) = { page: page_number, size: size, readability: true, markdown: true } query_object = Chen::Google.new(str,) return query_objects.to_results end |
.query_to_json(str, page_number = 1, size = 10) ⇒ Object
43 44 45 46 47 |
# File 'lib/chen.rb', line 43 def query_to_json(str, page_number = 1, size = 10) results = query(str, page_number, size) doc = ERB.new(Chen::Template) return doc.result end |
Instance Method Details
#to_results ⇒ Object
copied mostly from the “show” method
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/chen.rb', line 51 def to_results 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_one end return datas end |