Class: ComicVine::CVObjectList
- Defined in:
- lib/comic_vine/cv_list.rb
Overview
A paginated list of resources (e.g. from ComicVine::API.characters).
#next_page and #prev_page update the list in place, preserving the
original options (:filter, :sort, :field_list, ...).
Instance Attribute Summary collapse
-
#resource ⇒ String
readonly
The plural resource name this list was fetched from.
Attributes inherited from CVList
#cvos, #limit, #offset, #page_count, #total_count
Instance Method Summary collapse
-
#initialize(resp, resc, opts = {}) ⇒ CVObjectList
constructor
A new instance of CVObjectList.
-
#next_page ⇒ CVObjectList?
Advances to the next page, updating the list in place.
-
#prev_page ⇒ CVObjectList?
Steps back to the previous page, updating the list in place.
Methods inherited from CVList
Constructor Details
#initialize(resp, resc, opts = {}) ⇒ CVObjectList
Returns a new instance of CVObjectList.
66 67 68 69 70 71 72 |
# File 'lib/comic_vine/cv_list.rb', line 66 def initialize(resp, resc, opts = {}) super(resp) @resource = resc @opts = opts || {} @cvos = resp['results'].map { |r| ComicVine::CVObject.new(r) } end |
Instance Attribute Details
#resource ⇒ String (readonly)
Returns the plural resource name this list was fetched from.
61 62 63 |
# File 'lib/comic_vine/cv_list.rb', line 61 def resource @resource end |
Instance Method Details
#next_page ⇒ CVObjectList?
Advances to the next page, updating the list in place.
78 79 80 81 82 83 |
# File 'lib/comic_vine/cv_list.rb', line 78 def next_page return nil if (@offset + @page_count) >= @total_count update_ivals(ComicVine::API.send(@resource, @opts.merge(:limit => @limit, :offset => (@offset + @limit)))) self end |
#prev_page ⇒ CVObjectList?
Steps back to the previous page, updating the list in place.
89 90 91 92 93 94 |
# File 'lib/comic_vine/cv_list.rb', line 89 def prev_page return nil if @offset == 0 update_ivals(ComicVine::API.send(@resource, @opts.merge(:limit => @limit, :offset => [@offset - @limit, 0].max))) self end |