Class: Starwars::Cursor
- Inherits:
-
Base
- Object
- OpenStruct
- Base
- Starwars::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/starwars/cursor.rb
Overview
A pagination container for starwars
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
-
#each_page {|response| ... } ⇒ Enumerable?
(also: #each)
Yields the subsequent page responses to a given block.
-
#last_page? ⇒ Boolean
Checks wheather this is the last page.
-
#next_page ⇒ Starwars::Base
Returns the next page.
-
#next_page? ⇒ Boolean
Checks wheather this there is more pages.
-
#number_of_pages ⇒ Integer
A wrapper to get the pages count from the api.
-
#results ⇒ Array
(also: #items)
A wrapper to get the results within a page.
Methods inherited from Base
#==, #created, #edited, fetch, #fetch, fetch_all, #id, #request_attributes, #url
Methods inherited from OpenStruct
Instance Method Details
#each_page {|response| ... } ⇒ Enumerable? Also known as: each
Yields the subsequent page responses to a given block
93 94 95 96 |
# File 'lib/starwars/cursor.rb', line 93 def each_page return to_enum(__callee__) unless block_given? yield(next_page) until last_page? end |
#last_page? ⇒ Boolean
Checks wheather this is the last page
59 60 61 |
# File 'lib/starwars/cursor.rb', line 59 def last_page? !next_page? end |
#next_page ⇒ Starwars::Base
Returns the next page
78 79 80 81 |
# File 'lib/starwars/cursor.rb', line 78 def next_page return if last_page? perform_request end |
#next_page? ⇒ Boolean
Checks wheather this there is more pages
68 69 70 |
# File 'lib/starwars/cursor.rb', line 68 def next_page? !self.next.nil? end |
#number_of_pages ⇒ Integer
A wrapper to get the pages count from the api
39 40 41 |
# File 'lib/starwars/cursor.rb', line 39 def number_of_pages self[:count] end |
#results ⇒ Array Also known as: items
Note:
This wrapper is needed to define the items alias method
A wrapper to get the results within a page
50 51 52 |
# File 'lib/starwars/cursor.rb', line 50 def results self[:results] end |