Class: Fulfillment::PagedResult
- Inherits:
-
Object
- Object
- Fulfillment::PagedResult
- Includes:
- Enumerable
- Defined in:
- lib/fulfillment/paged_result.rb
Instance Attribute Summary collapse
-
#first_page_num ⇒ Object
readonly
Returns the value of attribute first_page_num.
Class Method Summary collapse
-
.construct(first_page_num, &api_caller_proc) ⇒ Object
Alternative constructor that takes a block rather than a Proc instance.
Instance Method Summary collapse
- #each {|enveloped_page[:data]| ... } ⇒ Object
-
#initialize(first_page_num, api_caller_proc) ⇒ PagedResult
constructor
first_page_number is the starting page for the associated API call.
- #pages ⇒ Object
- #results ⇒ Object
Constructor Details
#initialize(first_page_num, api_caller_proc) ⇒ PagedResult
first_page_number is the starting page for the associated API call. api_caller_proc is a Proc that returns a hash (of the type returned
by Exchange::PagingEnvelope.envelope). Calling the proc and passing
it a page_number should return an enveloped API call result.
13 14 15 16 |
# File 'lib/fulfillment/paged_result.rb', line 13 def initialize(first_page_num, api_caller_proc) @first_page_num = first_page_num @api_caller_proc = api_caller_proc end |
Instance Attribute Details
#first_page_num ⇒ Object (readonly)
Returns the value of attribute first_page_num.
5 6 7 |
# File 'lib/fulfillment/paged_result.rb', line 5 def first_page_num @first_page_num end |
Class Method Details
.construct(first_page_num, &api_caller_proc) ⇒ Object
Alternative constructor that takes a block rather than a Proc instance
40 41 42 |
# File 'lib/fulfillment/paged_result.rb', line 40 def construct(first_page_num, &api_caller_proc) new(first_page_num, api_caller_proc) end |
Instance Method Details
#each {|enveloped_page[:data]| ... } ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fulfillment/paged_result.rb', line 26 def each page_num = @first_page_num enveloped_page = @api_caller_proc.call(page_num) yield enveloped_page[:data] while (page_num < enveloped_page[:total_pages]) page_num += 1 enveloped_page = @api_caller_proc.call(page_num) yield enveloped_page[:data] end end |
#pages ⇒ Object
18 19 20 |
# File 'lib/fulfillment/paged_result.rb', line 18 def pages entries end |
#results ⇒ Object
22 23 24 |
# File 'lib/fulfillment/paged_result.rb', line 22 def results pages.flatten end |