Class: FinchAPI::IndividualsPage
- Inherits:
-
Object
- Object
- FinchAPI::IndividualsPage
- Includes:
- Type::BasePage
- Defined in:
- lib/finch-api/individuals_page.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary collapse
- #auto_paging_each(&blk) ⇒ Object
-
#initialize(client:, req:, headers:, page_data:) ⇒ IndividualsPage
constructor
private
A new instance of IndividualsPage.
- #inspect ⇒ String
- #next_page ⇒ FinchAPI::IndividualsPage
- #next_page? ⇒ Boolean
Methods included from Type::BasePage
Constructor Details
#initialize(client:, req:, headers:, page_data:) ⇒ IndividualsPage
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of IndividualsPage.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/finch-api/individuals_page.rb', line 40 def initialize(client:, req:, headers:, page_data:) super model = req.fetch(:model) case page_data in {individuals: Array | nil => individuals} @individuals = individuals&.map { FinchAPI::Type::Converter.coerce(model, _1) } else end case page_data in {paging: Hash | nil => paging} @paging = FinchAPI::Type::Converter.coerce(FinchAPI::Models::Paging, paging) else end end |
Instance Attribute Details
#individuals ⇒ Array<Object>?
29 30 31 |
# File 'lib/finch-api/individuals_page.rb', line 29 def individuals @individuals end |
#paging ⇒ FinchAPI::Models::Paging
32 33 34 |
# File 'lib/finch-api/individuals_page.rb', line 32 def paging @paging end |
Instance Method Details
#auto_paging_each(&blk) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/finch-api/individuals_page.rb', line 75 def auto_paging_each(&blk) unless block_given? raise ArgumentError.new("A block must be given to ##{__method__}") end page = self loop do page.individuals&.each { blk.call(_1) } break unless page.next_page? page = page.next_page end end |
#inspect ⇒ String
88 89 90 |
# File 'lib/finch-api/individuals_page.rb', line 88 def inspect "#<#{self.class}:0x#{object_id.to_s(16)} individuals=#{individuals.inspect} paging=#{paging.inspect}>" end |
#next_page ⇒ FinchAPI::IndividualsPage
64 65 66 67 68 69 70 71 72 |
# File 'lib/finch-api/individuals_page.rb', line 64 def next_page unless next_page? = "No more pages available. Please check #next_page? before calling ##{__method__}" raise RuntimeError.new() end req = FinchAPI::Util.deep_merge(@req, {query: {offset: paging&.offset.to_i + individuals.to_a.size}}) @client.request(req) end |
#next_page? ⇒ Boolean
58 59 60 |
# File 'lib/finch-api/individuals_page.rb', line 58 def next_page? paging&.offset.to_i + individuals.to_a.size < paging&.count.to_i end |