Class: ComicVine::CVSearchList

Inherits:
CVList
  • Object
show all
Defined in:
lib/comic_vine/cv_list.rb

Overview

A paginated list of search results (from API.search).

Instance Attribute Summary collapse

Attributes inherited from CVList

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

Instance Method Summary collapse

Methods inherited from CVList

#each, #last, #page

Constructor Details

#initialize(resp, resc, query, opts = {}) ⇒ CVSearchList

Returns a new instance of CVSearchList.

Parameters:

  • resp (Hash)

    a search response from the API

  • resc (String)

    the resource type(s) searched

  • query (String)

    the search query

  • opts (Hash) (defaults to: {})

    the options the search was made with



108
109
110
111
112
113
114
115
# File 'lib/comic_vine/cv_list.rb', line 108

def initialize(resp, resc, query, opts = {})
  super(resp)

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

Instance Attribute Details

#queryString (readonly)

Returns the search query.

Returns:

  • (String)

    the search query



102
103
104
# File 'lib/comic_vine/cv_list.rb', line 102

def query
  @query
end

#resourceString (readonly)

Returns the resource type(s) searched.

Returns:

  • (String)

    the resource type(s) searched



100
101
102
# File 'lib/comic_vine/cv_list.rb', line 100

def resource
  @resource
end

Instance Method Details

#next_pageCVSearchList?

Advances to the next page of results, updating the list in place.

Returns:

  • (CVSearchList, nil)

    self, or nil if already on the last page

Raises:



121
122
123
124
125
126
# File 'lib/comic_vine/cv_list.rb', line 121

def next_page
  return nil if (@offset + @page_count) >= @total_count

  update_ivals(ComicVine::API.search(@resource, @query, @opts.merge(:limit => @limit, :page => page + 1)))
  self
end

#prev_pageCVSearchList?

Steps back to the previous page of results, updating the list in place.

Returns:

  • (CVSearchList, nil)

    self, or nil if already on the first page

Raises:



132
133
134
135
136
137
# File 'lib/comic_vine/cv_list.rb', line 132

def prev_page
  return nil if @offset == 0

  update_ivals(ComicVine::API.search(@resource, @query, @opts.merge(:limit => @limit, :page => page - 1)))
  self
end