Class: ComicVine::CVList
- Inherits:
-
Object
- Object
- ComicVine::CVList
- Includes:
- Enumerable
- Defined in:
- lib/comic_vine/cv_list.rb
Overview
Base class for paginated result lists. Carries the count values from the
API response (total_count, page_count, offset, limit) and includes
Enumerable over the contained CVObjects.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cvos ⇒ Array<CVObject>
readonly
The objects on the current page.
-
#limit ⇒ Integer
readonly
Page size.
-
#offset ⇒ Integer
readonly
Offset of the current page.
-
#page_count ⇒ Integer
readonly
Results on the current page.
-
#total_count ⇒ Integer
readonly
Total results across all pages.
Instance Method Summary collapse
-
#each ⇒ Object
Yields each CVObject on the current page.
-
#initialize(resp) ⇒ CVList
constructor
A new instance of CVList.
-
#last ⇒ CVObject?
The last object on the current page.
-
#page ⇒ Integer
The current page number (1-based).
Constructor Details
#initialize(resp) ⇒ CVList
Returns a new instance of CVList.
22 23 24 25 26 27 |
# File 'lib/comic_vine/cv_list.rb', line 22 def initialize(resp) @total_count = resp['number_of_total_results'] @page_count = resp['number_of_page_results'] @offset = resp['offset'] @limit = resp['limit'] end |
Instance Attribute Details
#cvos ⇒ Array<CVObject> (readonly)
Returns the objects on the current page.
19 20 21 |
# File 'lib/comic_vine/cv_list.rb', line 19 def cvos @cvos end |
#limit ⇒ Integer (readonly)
Returns page size.
17 18 19 |
# File 'lib/comic_vine/cv_list.rb', line 17 def limit @limit end |
#offset ⇒ Integer (readonly)
Returns offset of the current page.
15 16 17 |
# File 'lib/comic_vine/cv_list.rb', line 15 def offset @offset end |
#page_count ⇒ Integer (readonly)
Returns results on the current page.
13 14 15 |
# File 'lib/comic_vine/cv_list.rb', line 13 def page_count @page_count end |
#total_count ⇒ Integer (readonly)
Returns total results across all pages.
11 12 13 |
# File 'lib/comic_vine/cv_list.rb', line 11 def total_count @total_count end |
Instance Method Details
#each ⇒ Object
Yields each ComicVine::CVObject on the current page.
30 31 32 |
# File 'lib/comic_vine/cv_list.rb', line 30 def each(&) @cvos.each(&) end |
#last ⇒ CVObject?
Returns the last object on the current page.
35 36 37 |
# File 'lib/comic_vine/cv_list.rb', line 35 def last @cvos.last end |
#page ⇒ Integer
Returns the current page number (1-based).
40 41 42 |
# File 'lib/comic_vine/cv_list.rb', line 40 def page (@offset / @limit) + 1 end |