Class: Fotolia::SearchResultSet
- Inherits:
-
Object
- Object
- Fotolia::SearchResultSet
- Defined in:
- lib/fotolia/search_result_set.rb
Overview
Holds all media returned by each method relying on Fotolia::Base#search.
Acts like an Array as all missing methods are passed to the instance variable @media which is an Array in fact.
Fotolia::Base#search doesn’t return an Array but a SearchResultSet insteaad, because Fotolia’s API restricts the number of media returned per search query to a maximum of 64. The SearchResultSet allows you to easily fetch all media – the results are parted in pages.
You may access these pages by calling pages
on the SearchResultSet. The pages are held in an Fotolia::SearchResultSet::Pages object.
Defined Under Namespace
Classes: Pages
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
<Integer> The number of the current page.
-
#pages ⇒ Object
readonly
<Fotolia::SearchResultSet::Pages> The Pages object holding all pages for this search.
-
#per_page ⇒ Object
readonly
<Integer> The number of media per page.
-
#total ⇒ Object
readonly
<Integer> The total number of found media for this search as returned by Fotolia.
Instance Method Summary collapse
-
#initialize(fotolia_client, options, pages_obj = nil) ⇒ SearchResultSet
constructor
Parameters fotolia_client:: A Fotolia::Base object options:: The options hash passed to Base#search pages_obj (optional):: Don’t create a new Pages object, but use an existing one.
-
#method_missing(method, *args, &block) ⇒ Object
:nodoc:.
-
#next_page ⇒ Object
Returns the next page for the current search or nil if any.
-
#previous_page ⇒ Object
Returns the previous page for the current search or nil if any.
Constructor Details
#initialize(fotolia_client, options, pages_obj = nil) ⇒ SearchResultSet
Parameters
- fotolia_client
-
A Fotolia::Base object
- options
-
The options hash passed to Base#search
- pages_obj (optional)
-
Don’t create a new Pages object, but use an existing one. Used internally for page caching.
90 91 92 93 94 95 |
# File 'lib/fotolia/search_result_set.rb', line 90 def initialize(fotolia_client, , pages_obj = nil) @fotolia = fotolia_client @options = @pages = pages_obj if(pages_obj.kind_of?(Pages)) search end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
:nodoc:
113 114 115 |
# File 'lib/fotolia/search_result_set.rb', line 113 def method_missing(method, *args, &block) #:nodoc: @media.respond_to?(method) ? @media.send(method, *args, &block) : super end |
Instance Attribute Details
#page ⇒ Object (readonly)
<Integer> The number of the current page.
73 74 75 |
# File 'lib/fotolia/search_result_set.rb', line 73 def page @page end |
#pages ⇒ Object (readonly)
<Fotolia::SearchResultSet::Pages> The Pages object holding all pages for this search.
76 77 78 |
# File 'lib/fotolia/search_result_set.rb', line 76 def pages @pages end |
#per_page ⇒ Object (readonly)
<Integer> The number of media per page.
78 79 80 |
# File 'lib/fotolia/search_result_set.rb', line 78 def per_page @per_page end |
#total ⇒ Object (readonly)
<Integer> The total number of found media for this search as returned by
Fotolia. You shouldn't rely on this value too badly, Fotolia
doesn't seem to be too correct about it...
82 83 84 |
# File 'lib/fotolia/search_result_set.rb', line 82 def total @total end |
Instance Method Details
#next_page ⇒ Object
Returns the next page for the current search or nil if any.
108 109 110 111 |
# File 'lib/fotolia/search_result_set.rb', line 108 def next_page return nil unless(@media) self.pages[@page + 2] if(@page < @total) end |
#previous_page ⇒ Object
Returns the previous page for the current search or nil if any.
100 101 102 103 |
# File 'lib/fotolia/search_result_set.rb', line 100 def previous_page return nil unless(@media) self.pages[@page - 2] if(@page > 1) end |