Class: DaisybillApi::Ext::PageableCollection
- Inherits:
-
Object
- Object
- DaisybillApi::Ext::PageableCollection
- Includes:
- Enumerable
- Defined in:
- lib/daisybill_api/ext/pageable_collection.rb
Overview
Provides a paginated collection of objects that can iterated upon:
bp = DaisybillApi::Models::BillingProvider.find(14) # => <DaisyBillApi::Models::BillingProvider>
patients = bp.patients # => #<DaisybillApi::Ext::PageableCollection>
until patients.next_page.nil? do
puts patients.map(&:id)
patients = patients.next_page
end
# => [1, 2, 3, 4, 5]
Instance Method Summary collapse
-
#current_page_number ⇒ Integer
Returns the current page number.
- #each(&block) ⇒ Object
-
#first_page ⇒ PageableCollection
Returns the first page of the collection.
-
#initialize(entries, options = {}) ⇒ PageableCollection
constructor
A new instance of PageableCollection.
- #inspect ⇒ Object
-
#last_page ⇒ PageableCollection
Returns the last page in the collection.
-
#next_page ⇒ PageableCollection?
Returns the next page in the collection.
-
#previous_page ⇒ PageableCollection?
Returns the previous page in the collection.
Constructor Details
#initialize(entries, options = {}) ⇒ PageableCollection
Returns a new instance of PageableCollection.
17 18 19 20 |
# File 'lib/daisybill_api/ext/pageable_collection.rb', line 17 def initialize(entries, = {}) @entries = entries @options = end |
Instance Method Details
#current_page_number ⇒ Integer
Returns the current page number
@providers.current_page_number # => 1
79 80 81 |
# File 'lib/daisybill_api/ext/pageable_collection.rb', line 79 def current_page_number retrieve_header_value(:x_page) end |
#each(&block) ⇒ Object
26 27 28 29 30 |
# File 'lib/daisybill_api/ext/pageable_collection.rb', line 26 def each(&block) entries.each do |entry| block.call(entry) end end |
#first_page ⇒ PageableCollection
Returns the first page of the collection
@patients = DaisybillApi::Models::Patient.all(billing_provider_id: 25) # => #<DaisybillApi::Ext::PageableCollection>
@patients.first_page # => #<DaisybillApi::Ext::PageableCollection>
39 40 41 |
# File 'lib/daisybill_api/ext/pageable_collection.rb', line 39 def first_page resource_class.all() end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/daisybill_api/ext/pageable_collection.rb', line 22 def inspect "#<DaisybillApi::Ext::PageableCollection entries: #{entries.to_s[1..80]}..., previous_page: #{previous_page_number}, current_page: #{current_page_number}, next_page: #{next_page_number} >" end |
#last_page ⇒ PageableCollection
Returns the last page in the collection
@patients.last_page # => #<DaisybillApi::Ext::PageableCollection>
48 49 50 |
# File 'lib/daisybill_api/ext/pageable_collection.rb', line 48 def last_page resource_class.all(.merge(page: total_page_count)) end |
#next_page ⇒ PageableCollection?
Returns the next page in the collection
@providers.next_page # => #<DaisybillApi::Ext::PageableCollection>
57 58 59 60 61 |
# File 'lib/daisybill_api/ext/pageable_collection.rb', line 57 def next_page if next_page_number resource_class.all(.merge(page: next_page_number)) end end |
#previous_page ⇒ PageableCollection?
Returns the previous page in the collection
@providers.previous_page # => #<DaisybillApi::Ext::PageableCollection>
68 69 70 71 72 |
# File 'lib/daisybill_api/ext/pageable_collection.rb', line 68 def previous_page if previous_page_number resource_class.all(.merge(page: previous_page_number)) end end |