Class: ComicVine::List

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/comicvine/list.rb

Overview

Enumerable list for multiple ComicVine results

Since:

  • 0.1.0

Direct Known Subclasses

ResourceList, SearchResults

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resp) ⇒ List

Returns a new instance of List.

Since:

  • 0.1.0



15
16
17
18
19
20
# File 'lib/comicvine/list.rb', line 15

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

#cvosObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/comicvine/list.rb', line 13

def cvos
  @cvos
end

#limitObject (readonly)

Since:

  • 0.1.0



12
13
14
# File 'lib/comicvine/list.rb', line 12

def limit
  @limit
end

#offsetObject (readonly)

Since:

  • 0.1.0



11
12
13
# File 'lib/comicvine/list.rb', line 11

def offset
  @offset
end

#page_countObject (readonly)

Since:

  • 0.1.0



10
11
12
# File 'lib/comicvine/list.rb', line 10

def page_count
  @page_count
end

#total_countObject (readonly)

Since:

  • 0.1.0



9
10
11
# File 'lib/comicvine/list.rb', line 9

def total_count
  @total_count
end

Instance Method Details

#eachObject

Since:

  • 0.1.0



22
23
24
# File 'lib/comicvine/list.rb', line 22

def each
  @cvos.each { |c| yield c }
end

#has_more?true, false

Returns if there are more pages to load

Returns:

  • (true, false)

Since:

  • 0.1.3



46
47
48
# File 'lib/comicvine/list.rb', line 46

def has_more?
  self.total_pages > self.page ? true : false
end

#lastObject

Since:

  • 0.1.0



26
27
28
# File 'lib/comicvine/list.rb', line 26

def last
  @cvos.last
end

#pageInteger

Returns the current page the object is on

Returns:

  • (Integer)

Since:

  • 0.1.0



32
33
34
# File 'lib/comicvine/list.rb', line 32

def page
  (self.offset / self.limit) + 1
end

#total_pagesInteger

Returns the total number of pages available

Returns:

  • (Integer)

    Total number of pages

Since:

  • 0.1.3



39
40
41
# File 'lib/comicvine/list.rb', line 39

def total_pages
  (self.total_count / self.limit) + 1
end