Class: RubyWebSearch::Yahoo::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-web-search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(google_raw_response = {}) ⇒ Response

Returns a new instance of Response.



338
339
340
# File 'lib/ruby-web-search.rb', line 338

def initialize(google_raw_response={})
  process(google_raw_response) unless google_raw_response.empty?
end

Instance Attribute Details

#estimated_result_countObject (readonly)

Returns the value of attribute estimated_result_count.



337
338
339
# File 'lib/ruby-web-search.rb', line 337

def estimated_result_count
  @estimated_result_count
end

#queryObject (readonly)

Returns the value of attribute query.



337
338
339
# File 'lib/ruby-web-search.rb', line 337

def query
  @query
end

#resultsObject (readonly)

Returns the value of attribute results.



337
338
339
# File 'lib/ruby-web-search.rb', line 337

def results
  @results
end

#sizeObject (readonly)

Returns the value of attribute size.



337
338
339
# File 'lib/ruby-web-search.rb', line 337

def size
  @size
end

#statusObject (readonly)

Returns the value of attribute status.



337
338
339
# File 'lib/ruby-web-search.rb', line 337

def status
  @status
end

Instance Method Details

#limit(req_size) ⇒ Object



360
361
362
363
# File 'lib/ruby-web-search.rb', line 360

def limit(req_size)
  @results = @results[0...req_size]
  self
end

#process(google_raw_response = {}) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/ruby-web-search.rb', line 342

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