Class: YahooSiteExplorer::PageData

Inherits:
ResultsContainer show all
Defined in:
lib/yahoo_site_explorer/page_data.rb

Instance Attribute Summary

Attributes inherited from ResultsContainer

#first_result_position, #results, #total_results_available, #total_results_returned

Instance Method Summary collapse

Methods inherited from ResultsContainer

#initialize

Constructor Details

This class inherits a constructor from YahooSiteExplorer::ResultsContainer

Instance Method Details

#eachObject

This method will step through all of the results supplied by Yahoo! for your given query. This method acts like a cursor and will automatically re-query Yahoo! after for any subsequent set of results results (i.e. if your original query asked for 50 results at a time, this method will act as a cursor, pulling 50 results at a time over the entire resulting collection).



16
17
18
19
20
21
22
23
24
25
# File 'lib/yahoo_site_explorer/page_data.rb', line 16

def each
  page_data = self
  records   = self.results
  while !records.empty?
    records.each { |record| yield record }
    page_data = page_data.next_set
    records   = page_data.results
  end
  self
end

#next_setObject

Returns the next PageData set based on available results from Yahoo! specific to the current query and request options.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/yahoo_site_explorer/page_data.rb', line 31

def next_set #:nodoc:
  if next_starting_position <= @total_results_available
    @service.page_data( @request_options.delete(:url), 
                        @request_options.merge({
                          :start => next_starting_position
                        })
                      )
  else
    PageData.new(@service, @request_options, {
      :total_results_available  => @total_results_available,
      :total_results_returned   => 0,
      :first_result_position    => next_starting_position,
      :results                  => []
    })
  end
end