Class: Flickr::Photos
- Inherits:
-
Object
- Object
- Flickr::Photos
- Includes:
- Enumerable
- Defined in:
- lib/simple-flickr/photos.rb
Overview
A collection of Photos.
Instance Method Summary collapse
-
#[](n) ⇒ Object
Allow Photos to be accessed as an Array.
- #current_page ⇒ Object
-
#each ⇒ Object
Iterate through all the Flickr::Photo objects.
-
#empty? ⇒ Boolean
Is this collection of photos empty?.
-
#initialize(result_xml, client) ⇒ Photos
constructor
Create a new Flickr::Photos collection using the provided Hpricot::Elem object, which should contain an appropriate Photo response in XML from Flickr.
- #next_page ⇒ Object
- #offset ⇒ Object
- #per_page ⇒ Object
- #previous_page ⇒ Object
-
#size ⇒ Object
(also: #length)
How big is this collection?.
- #total_entries ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(result_xml, client) ⇒ Photos
Create a new Flickr::Photos collection using the provided Hpricot::Elem object, which should contain an appropriate Photo response in XML from Flickr.
36 37 38 39 |
# File 'lib/simple-flickr/photos.rb', line 36 def initialize( result_xml, client ) @photos = result_xml.search( 'photo' ).collect { |xml| Flickr::Photo.new( xml, client ) } @attributes = result_xml.attributes end |
Instance Method Details
#[](n) ⇒ Object
Allow Photos to be accessed as an Array
58 59 60 |
# File 'lib/simple-flickr/photos.rb', line 58 def [](n) to_a[n] end |
#current_page ⇒ Object
10 11 12 |
# File 'lib/simple-flickr/photos.rb', line 10 def current_page @attributes['page'].to_i end |
#each ⇒ Object
Iterate through all the Flickr::Photo objects.
42 43 44 |
# File 'lib/simple-flickr/photos.rb', line 42 def each @photos.each { |photo| yield photo } end |
#empty? ⇒ Boolean
Is this collection of photos empty?
47 48 49 |
# File 'lib/simple-flickr/photos.rb', line 47 def empty? to_a.empty? end |
#next_page ⇒ Object
26 27 28 |
# File 'lib/simple-flickr/photos.rb', line 26 def next_page total_pages > current_page ? current_page+1 : nil end |
#offset ⇒ Object
6 7 8 |
# File 'lib/simple-flickr/photos.rb', line 6 def offset (current_page-1) * per_page end |
#per_page ⇒ Object
14 15 16 |
# File 'lib/simple-flickr/photos.rb', line 14 def per_page (@attributes['perpage'] || @attributes['per_page']).to_i end |
#previous_page ⇒ Object
30 31 32 |
# File 'lib/simple-flickr/photos.rb', line 30 def previous_page current_page > 1 ? current_page-1 : nil end |
#size ⇒ Object Also known as: length
How big is this collection?
52 53 54 |
# File 'lib/simple-flickr/photos.rb', line 52 def size to_a.size end |
#total_entries ⇒ Object
18 19 20 |
# File 'lib/simple-flickr/photos.rb', line 18 def total_entries @attributes['total'].to_i end |
#total_pages ⇒ Object
22 23 24 |
# File 'lib/simple-flickr/photos.rb', line 22 def total_pages (total_entries.to_f / per_page).ceil end |