Class: Jikanrb::Pagination::PaginationInfo
- Inherits:
-
Object
- Object
- Jikanrb::Pagination::PaginationInfo
- Defined in:
- lib/jikanrb/pagination.rb
Overview
Represents pagination information from an API response
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#has_next_page ⇒ Object
readonly
Returns the value of attribute has_next_page.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#last_visible_page ⇒ Object
readonly
Returns the value of attribute last_visible_page.
Instance Method Summary collapse
-
#current_item_count ⇒ Integer
Get current item count.
-
#has_next_page? ⇒ Boolean
Check if there's a next page.
-
#has_previous_page? ⇒ Boolean
Check if there's a previous page.
-
#initialize(response) ⇒ PaginationInfo
constructor
A new instance of PaginationInfo.
-
#next_page ⇒ Integer?
Get next page number.
-
#per_page ⇒ Integer
Get number of items per page.
-
#previous_page ⇒ Integer?
Get previous page number.
-
#total_items ⇒ Integer
Get total number of items.
-
#total_pages ⇒ Integer
Get total number of pages.
Constructor Details
#initialize(response) ⇒ PaginationInfo
Returns a new instance of PaginationInfo.
24 25 26 27 28 29 30 |
# File 'lib/jikanrb/pagination.rb', line 24 def initialize(response) @pagination = response['pagination'] || {} @current_page = @pagination['current_page'] || 1 @last_visible_page = @pagination['last_visible_page'] || 1 @has_next_page = @pagination['has_next_page'] || false @items = @pagination['items'] || {} end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
21 22 23 |
# File 'lib/jikanrb/pagination.rb', line 21 def current_page @current_page end |
#has_next_page ⇒ Object (readonly)
Returns the value of attribute has_next_page.
21 22 23 |
# File 'lib/jikanrb/pagination.rb', line 21 def has_next_page @has_next_page end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
21 22 23 |
# File 'lib/jikanrb/pagination.rb', line 21 def items @items end |
#last_visible_page ⇒ Object (readonly)
Returns the value of attribute last_visible_page.
21 22 23 |
# File 'lib/jikanrb/pagination.rb', line 21 def last_visible_page @last_visible_page end |
Instance Method Details
#current_item_count ⇒ Integer
Get current item count
76 77 78 |
# File 'lib/jikanrb/pagination.rb', line 76 def current_item_count @items['count'] || 0 end |
#has_next_page? ⇒ Boolean
Check if there's a next page
34 35 36 |
# File 'lib/jikanrb/pagination.rb', line 34 def has_next_page? @has_next_page end |
#has_previous_page? ⇒ Boolean
Check if there's a previous page
40 41 42 |
# File 'lib/jikanrb/pagination.rb', line 40 def has_previous_page? @current_page > 1 end |
#next_page ⇒ Integer?
Get next page number
46 47 48 |
# File 'lib/jikanrb/pagination.rb', line 46 def next_page has_next_page? ? @current_page + 1 : nil end |
#per_page ⇒ Integer
Get number of items per page
64 65 66 |
# File 'lib/jikanrb/pagination.rb', line 64 def per_page @items['per_page'] || 25 end |
#previous_page ⇒ Integer?
Get previous page number
52 53 54 |
# File 'lib/jikanrb/pagination.rb', line 52 def previous_page has_previous_page? ? @current_page - 1 : nil end |
#total_items ⇒ Integer
Get total number of items
70 71 72 |
# File 'lib/jikanrb/pagination.rb', line 70 def total_items @items['total'] || 0 end |
#total_pages ⇒ Integer
Get total number of pages
58 59 60 |
# File 'lib/jikanrb/pagination.rb', line 58 def total_pages @last_visible_page end |