Class: RubyWebSearch::Google::Response
- Inherits:
-
Object
- Object
- RubyWebSearch::Google::Response
- Defined in:
- lib/ruby-web-search.rb
Instance Attribute Summary collapse
-
#estimated_result_count ⇒ Object
readonly
Returns the value of attribute estimated_result_count.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(google_raw_response = {}) ⇒ Response
constructor
A new instance of Response.
- #limit(req_size) ⇒ Object
- #process(google_raw_response = {}) ⇒ Object
Constructor Details
#initialize(google_raw_response = {}) ⇒ Response
Returns a new instance of Response.
164 165 166 |
# File 'lib/ruby-web-search.rb', line 164 def initialize(google_raw_response={}) process(google_raw_response) unless google_raw_response.empty? end |
Instance Attribute Details
#estimated_result_count ⇒ Object (readonly)
Returns the value of attribute estimated_result_count.
163 164 165 |
# File 'lib/ruby-web-search.rb', line 163 def estimated_result_count @estimated_result_count end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
163 164 165 |
# File 'lib/ruby-web-search.rb', line 163 def query @query end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
163 164 165 |
# File 'lib/ruby-web-search.rb', line 163 def results @results end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
163 164 165 |
# File 'lib/ruby-web-search.rb', line 163 def size @size end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
163 164 165 |
# File 'lib/ruby-web-search.rb', line 163 def status @status end |
Instance Method Details
#limit(req_size) ⇒ Object
186 187 188 189 |
# File 'lib/ruby-web-search.rb', line 186 def limit(req_size) @results = @results[0...req_size] self end |
#process(google_raw_response = {}) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/ruby-web-search.rb', line 168 def process(google_raw_response={}) @query ||= google_raw_response[:query] @size ||= google_raw_response[:size] @results ||= [] @status = google_raw_response["responseStatus"] if google_raw_response["responseData"] && status && status == 200 estimated_result_count ||= google_raw_response["cursor"]["estimatedResultCount"] if google_raw_response["cursor"] @results += google_raw_response["responseData"]["results"].map do |r| { :title => r["titleNoFormatting"], :url => r["unescapedUrl"], :cache_url => r["cacheUrl"], :content => r["content"], :domain => r["visibleUrl"] } end end def limit(req_size) @results = @results[0...req_size] self end end |