Class: Net::Flickr::List

Inherits:
Object
  • Object
show all
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

PhotoList

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pageObject

Returns the value of attribute page.



38
39
40
# File 'lib/net/flickr/list.rb', line 38

def page
  @page
end

#pagesObject (readonly)

Returns the value of attribute pages.



38
39
40
# File 'lib/net/flickr/list.rb', line 38

def pages
  @pages
end

#per_pageObject

Returns the value of attribute per_page.



38
39
40
# File 'lib/net/flickr/list.rb', line 38

def per_page
  @per_page
end

#totalObject (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

#eachObject



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


68
69
70
# File 'lib/net/flickr/list.rb', line 68

def last_page?
  return @page == @pages
end

#nextObject

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

#previousObject 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