Class: Fotolia::SearchResultSet::Pages
- Inherits:
-
Object
- Object
- Fotolia::SearchResultSet::Pages
- Includes:
- Enumerable
- Defined in:
- lib/fotolia/search_result_set.rb
Overview
Holds all pages for one search result. You may use all methods offered by Enumberable.
Instance Method Summary collapse
-
#[](n) ⇒ Object
Access one page of a search result.
-
#each ⇒ Object
Yields the given block for every page.
-
#initialize(fotolia_client, options, pages, result_set) ⇒ Pages
constructor
Parameters fotolia_client:: Fotolia::Base object options:: The options hash given to Base#search pages:: The total number of pages.
-
#length ⇒ Object
(also: #count)
Returns the number of pages.
Constructor Details
#initialize(fotolia_client, options, pages, result_set) ⇒ Pages
Parameters
- fotolia_client
-
Fotolia::Base object
- options
-
The options hash given to Base#search
- pages
-
The total number of pages.
- result_set
-
The SearchResultSet the call of Base#search returned.
32 33 34 35 36 37 38 |
# File 'lib/fotolia/search_result_set.rb', line 32 def initialize(fotolia_client, , pages, result_set) @fotolia = fotolia_client @options = @pages = pages @result_sets = Array.new @result_sets[result_set.page - 1] = result_set end |
Instance Method Details
#[](n) ⇒ Object
Access one page of a search result.
Note that the numbering starts with 0.
Returns a SearchResultSet.
47 48 49 |
# File 'lib/fotolia/search_result_set.rb', line 47 def [] (n) @result_sets[n] ||= Fotolia::SearchResultSet.new(@fotolia, @options.merge({:page => (n + 1)}), self) end |
#each ⇒ Object
Yields the given block for every page.
54 55 56 57 58 59 |
# File 'lib/fotolia/search_result_set.rb', line 54 def each (0...@pages).each do |i| yield @result_sets[i] ||= Fotolia::SearchResultSet.new(@fotolia, @options.merge({:page => (i + 1)}), self) end self end |
#length ⇒ Object Also known as: count
Returns the number of pages.
64 65 66 |
# File 'lib/fotolia/search_result_set.rb', line 64 def length @pages end |