Class: RubyWebSearch::Yahoo::Response
- Inherits:
-
Object
- Object
- RubyWebSearch::Yahoo::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.
335 336 337 |
# File 'lib/ruby-web-search.rb', line 335 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.
334 335 336 |
# File 'lib/ruby-web-search.rb', line 334 def estimated_result_count @estimated_result_count end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
334 335 336 |
# File 'lib/ruby-web-search.rb', line 334 def query @query end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
334 335 336 |
# File 'lib/ruby-web-search.rb', line 334 def results @results end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
334 335 336 |
# File 'lib/ruby-web-search.rb', line 334 def size @size end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
334 335 336 |
# File 'lib/ruby-web-search.rb', line 334 def status @status end |
Instance Method Details
#limit(req_size) ⇒ Object
357 358 359 360 |
# File 'lib/ruby-web-search.rb', line 357 def limit(req_size) @results = @results[0...req_size] self end |
#process(google_raw_response = {}) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/ruby-web-search.rb', line 339 def process(google_raw_response={}) @query ||= google_raw_response[:query] @size ||= google_raw_response[:size] @results ||= [] @status = google_raw_response["ysearchresponse"]["responsecode"].to_i if google_raw_response["ysearchresponse"] if google_raw_response["ysearchresponse"] && google_raw_response["ysearchresponse"]["resultset_web"] && status && status == 200 estimated_result_count ||= google_raw_response["ysearchresponse"]["totalhits"] @results += google_raw_response["ysearchresponse"]["resultset_web"].map do |r| { :title => r["title"], :url => r["clickurl"], :cache_url => r["cacheUrl"], :content => r["abstract"], :domain => r["url"] } end end def limit(req_size) @results = @results[0...req_size] self end end |