Class: ComicVine::SearchResults

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

Overview

Class container for ComicVine search results

Since:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from List

#cvos, #limit, #offset, #page_count, #total_count

Instance Method Summary collapse

Methods inherited from List

#each, #has_more?, #last, #page, #total_pages

Constructor Details

#initialize(resp, resc, query) ⇒ SearchResults

Returns a new instance of SearchResults.

Since:

  • 0.1.0



98
99
100
101
102
103
104
# File 'lib/comicvine/list.rb', line 98

def initialize(resp, resc, query)
  super(resp)

  @resource = resc
  @query = query
  @cvos = resp['results'].map { |r| ComicVine::Resource.create_resource(r) }
end

Instance Attribute Details

#queryObject (readonly)

Since:

  • 0.1.0



96
97
98
# File 'lib/comicvine/list.rb', line 96

def query
  @query
end

#resourceObject (readonly)

Since:

  • 0.1.0



95
96
97
# File 'lib/comicvine/list.rb', line 95

def resource
  @resource
end

Instance Method Details

#next_pageObject

Moves search to the next offset results

Since:

  • 0.1.0



108
109
110
111
# File 'lib/comicvine/list.rb', line 108

def next_page
  return nil if (@offset + @page_count) >= @total_count
  update_ivals(ComicVine::API.search(@resource, @query, {:limit => @limit, :page => (((@offset + @page_count) / @limit) + 1)}))
end

#prev_pageObject

Moves search to the previous offset results

Since:

  • 0.1.0



115
116
117
118
# File 'lib/comicvine/list.rb', line 115

def prev_page
  return nil if @offset == 0
  update_ivals(ComicVine::API.search(@resource, @query, {:limit => @limit, :page => (@offset / @limit)}))
end