Class: ComicVine::CVList

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

CVObjectList, CVSearchList

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resp) ⇒ CVList

Returns a new instance of CVList.

Parameters:

  • resp (Hash)

    a list response from the API



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

#cvosArray<CVObject> (readonly)

Returns the objects on the current page.

Returns:

  • (Array<CVObject>)

    the objects on the current page



19
20
21
# File 'lib/comic_vine/cv_list.rb', line 19

def cvos
  @cvos
end

#limitInteger (readonly)

Returns page size.

Returns:

  • (Integer)

    page size



17
18
19
# File 'lib/comic_vine/cv_list.rb', line 17

def limit
  @limit
end

#offsetInteger (readonly)

Returns offset of the current page.

Returns:

  • (Integer)

    offset of the current page



15
16
17
# File 'lib/comic_vine/cv_list.rb', line 15

def offset
  @offset
end

#page_countInteger (readonly)

Returns results on the current page.

Returns:

  • (Integer)

    results on the current page



13
14
15
# File 'lib/comic_vine/cv_list.rb', line 13

def page_count
  @page_count
end

#total_countInteger (readonly)

Returns total results across all pages.

Returns:

  • (Integer)

    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

#eachObject

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

#lastCVObject?

Returns the last object on the current page.

Returns:

  • (CVObject, nil)

    the last object on the current page



35
36
37
# File 'lib/comic_vine/cv_list.rb', line 35

def last
  @cvos.last
end

#pageInteger

Returns the current page number (1-based).

Returns:

  • (Integer)

    the current page number (1-based)



40
41
42
# File 'lib/comic_vine/cv_list.rb', line 40

def page
  (@offset / @limit) + 1
end