Class: Net::Flickr::List
- Inherits:
-
Object
- Object
- Net::Flickr::List
- Includes:
- Enumerable
- Defined in:
- lib/net/flickr/list.rb
Overview
Base class for paginated lists.
Don’t instantiate this class yourself. It’s a base class extended by PhotoList
and others.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#[](index) ⇒ Object
– Public Instance Methods ++.
- #each ⇒ Object
-
#first_page? ⇒ Boolean
Returns
true
if the current page is the first page of the list,false
otherwise. -
#initialize(flickr, load_method, load_args) ⇒ List
constructor
A new instance of List.
-
#last_page? ⇒ Boolean
Returns
true
if the current page is the last page of the list,false
otherwise. -
#next ⇒ Object
Loads the next page in the list.
-
#previous ⇒ Object
(also: #prev)
Loads the previous page in the list.
Constructor Details
#initialize(flickr, load_method, load_args) ⇒ List
Returns a new instance of List.
40 41 42 43 44 45 46 |
# File 'lib/net/flickr/list.rb', line 40 def initialize(flickr, load_method, load_args) @flickr = flickr @load_method = load_method @load_args = load_args update_list end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
38 39 40 |
# File 'lib/net/flickr/list.rb', line 38 def page @page end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
38 39 40 |
# File 'lib/net/flickr/list.rb', line 38 def pages @pages end |
#per_page ⇒ Object
Returns the value of attribute per_page.
38 39 40 |
# File 'lib/net/flickr/list.rb', line 38 def per_page @per_page end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
38 39 40 |
# File 'lib/net/flickr/list.rb', line 38 def total @total end |
Instance Method Details
#[](index) ⇒ Object
– Public Instance Methods ++
52 53 54 |
# File 'lib/net/flickr/list.rb', line 52 def [](index) return @items[index] end |
#each ⇒ Object
56 57 58 |
# File 'lib/net/flickr/list.rb', line 56 def each @items.each {|item| yield item } end |
#first_page? ⇒ Boolean
Returns true
if the current page is the first page of the list, false
otherwise.
62 63 64 |
# File 'lib/net/flickr/list.rb', line 62 def first_page? return @page == 1 end |
#last_page? ⇒ Boolean
Returns true
if the current page is the last page of the list, false
otherwise.
68 69 70 |
# File 'lib/net/flickr/list.rb', line 68 def last_page? return @page == @pages end |
#next ⇒ Object
Loads the next page in the list.
73 74 75 76 77 78 79 80 |
# File 'lib/net/flickr/list.rb', line 73 def next if last_page? raise ListError, 'Already on the last page of the list' end @load_args['page'] = @page + 1 update_list end |
#previous ⇒ Object Also known as: prev
Loads the previous page in the list.
104 105 106 107 108 109 110 111 |
# File 'lib/net/flickr/list.rb', line 104 def previous if first_page? raise ListError, 'Already on the first page of the list' end @load_args['page'] = @page - 1 update_list end |