Class: WscSdk::Pagination
- Inherits:
-
Object
- Object
- WscSdk::Pagination
- Defined in:
- lib/wsc_sdk/pagination.rb
Overview
A class for handling the pagination data returned by endpoint lists.
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#page_first_index ⇒ Object
readonly
Returns the value of attribute page_first_index.
-
#page_last_index ⇒ Object
readonly
Returns the value of attribute page_last_index.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
-
#total_records ⇒ Object
readonly
Returns the value of attribute total_records.
Instance Method Summary collapse
-
#first_page ⇒ Integer, Nil
Get the number of the first page.
-
#first_page? ⇒ Boolean
Determine if the current page is the first page.
-
#initialize(pagination_data = {}) ⇒ Pagination
constructor
Get a new instance of the pagination class.
-
#last_page ⇒ Integer, Nil
Get the number of the last page.
-
#last_page? ⇒ Boolean
Determine if the current page is the last page.
-
#next_page ⇒ Integer, Nil
Get the number of the next page.
-
#previous_page ⇒ Integer, Nil
Get the number of the previous page.
Constructor Details
#initialize(pagination_data = {}) ⇒ Pagination
Get a new instance of the pagination class.
15 16 17 18 19 20 21 22 |
# File 'lib/wsc_sdk/pagination.rb', line 15 def initialize(pagination_data={}) @page = pagination_data.fetch(:page, 1) @per_page = pagination_data.fetch(:per_page, 1000) @total_pages = pagination_data.fetch(:total_pages, 1) @total_records = pagination_data.fetch(:total_records, -1) @page_first_index = pagination_data.fetch(:page_first_index, -1) @page_last_index = pagination_data.fetch(:page_last_index, -1) end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page
9 10 11 |
# File 'lib/wsc_sdk/pagination.rb', line 9 def page @page end |
#page_first_index ⇒ Object (readonly)
Returns the value of attribute page_first_index
9 10 11 |
# File 'lib/wsc_sdk/pagination.rb', line 9 def page_first_index @page_first_index end |
#page_last_index ⇒ Object (readonly)
Returns the value of attribute page_last_index
9 10 11 |
# File 'lib/wsc_sdk/pagination.rb', line 9 def page_last_index @page_last_index end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page
9 10 11 |
# File 'lib/wsc_sdk/pagination.rb', line 9 def per_page @per_page end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages
9 10 11 |
# File 'lib/wsc_sdk/pagination.rb', line 9 def total_pages @total_pages end |
#total_records ⇒ Object (readonly)
Returns the value of attribute total_records
9 10 11 |
# File 'lib/wsc_sdk/pagination.rb', line 9 def total_records @total_records end |
Instance Method Details
#first_page ⇒ Integer, Nil
Get the number of the first page
39 40 41 42 |
# File 'lib/wsc_sdk/pagination.rb', line 39 def first_page return nil if total_pages < 1 return 1 end |
#first_page? ⇒ Boolean
Determine if the current page is the first page
28 29 30 31 |
# File 'lib/wsc_sdk/pagination.rb', line 28 def first_page? return true if total_pages < 1 return (page == 1) end |
#last_page ⇒ Integer, Nil
Get the number of the last page
74 75 76 77 |
# File 'lib/wsc_sdk/pagination.rb', line 74 def last_page return nil if total_pages < 1 return total_pages end |
#last_page? ⇒ Boolean
Determine if the current page is the last page
83 84 85 86 |
# File 'lib/wsc_sdk/pagination.rb', line 83 def last_page? return true if total_pages < 1 return (page == total_pages) end |
#next_page ⇒ Integer, Nil
Get the number of the next page.
50 51 52 53 54 |
# File 'lib/wsc_sdk/pagination.rb', line 50 def next_page return nil if total_pages == -1 return nil if page == total_pages return page + 1 end |
#previous_page ⇒ Integer, Nil
Get the number of the previous page.
62 63 64 65 66 |
# File 'lib/wsc_sdk/pagination.rb', line 62 def previous_page return nil if total_pages < 1 return nil if page == 1 return page - 1 end |