Class: RubyWebSearch::Bing::Response
- Inherits:
-
Object
- Object
- RubyWebSearch::Bing::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.
509 510 511 |
# File 'lib/ruby-web-search.rb', line 509 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.
508 509 510 |
# File 'lib/ruby-web-search.rb', line 508 def estimated_result_count @estimated_result_count end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
508 509 510 |
# File 'lib/ruby-web-search.rb', line 508 def query @query end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
508 509 510 |
# File 'lib/ruby-web-search.rb', line 508 def results @results end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
508 509 510 |
# File 'lib/ruby-web-search.rb', line 508 def size @size end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
508 509 510 |
# File 'lib/ruby-web-search.rb', line 508 def status @status end |
Instance Method Details
#limit(req_size) ⇒ Object
534 535 536 537 |
# File 'lib/ruby-web-search.rb', line 534 def limit(req_size) @results = @results[0...req_size] self end |
#process(google_raw_response = {}) ⇒ Object
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/ruby-web-search.rb', line 513 def process(google_raw_response={}) @query ||= google_raw_response[:query] @size ||= google_raw_response[:size] @results ||= [] @status = 200 if google_raw_response["SearchResponse"] && google_raw_response["SearchResponse"]["Web"] && google_raw_response["SearchResponse"]["Web"]["Results"] && status && status == 200 estimated_result_count ||= google_raw_response["SearchResponse"]["Web"]["Total"] @results += google_raw_response["SearchResponse"]["Web"]["Results"].map do |r| { :title => r["Title"], :url => r["Url"], :cache_url => r["CacheUrl"], :content => r["Description"], :domain => r["DisplayUrl"] } end end def limit(req_size) @results = @results[0...req_size] self end end |