Class: XIVAPI::Paginator
- Inherits:
-
Object
- Object
- XIVAPI::Paginator
- Includes:
- Enumerable, HTTP
- Defined in:
- lib/xivapi/paginator.rb
Overview
Paginates XIVAPI results
Constant Summary
Constants included from HTTP
HTTP::API_BASE, HTTP::STAGING_API_BASE
Instance Method Summary collapse
-
#each ⇒ Object
An enumerator for XIVAPI results.
-
#initialize(client, params, endpoint, limit, body = nil, per_page = limit) ⇒ Paginator
constructor
A new instance of Paginator.
-
#next(page) ⇒ Object
The next page in the enumeration of results.
Methods included from HTTP
Constructor Details
#initialize(client, params, endpoint, limit, body = nil, per_page = limit) ⇒ Paginator
Returns a new instance of Paginator
13 14 15 16 17 18 19 |
# File 'lib/xivapi/paginator.rb', line 13 def initialize(client, params, endpoint, limit, body = nil, per_page = limit) @client = client @params = params.merge(limit: per_page) @endpoint = endpoint @limit = limit @body = body end |
Instance Method Details
#each ⇒ Object
An enumerator for XIVAPI results
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/xivapi/paginator.rb', line 22 def each total = 0 next_page = 1 while next_page && total < @limit page = self.next(next_page) page.results.take(@limit - total).each { |result| yield result } next_page = page.next_page total += page.results.size end end |