Class: Riveter::RunsPage
- Inherits:
-
Object
- Object
- Riveter::RunsPage
- Includes:
- Enumerable
- Defined in:
- lib/riveter/page.rb
Overview
One page of runs. #each iterates the page; #auto_paging_each walks every following page too.
Instance Attribute Summary collapse
-
#monitor_id ⇒ Object
readonly
Returns the value of attribute monitor_id.
-
#pagination ⇒ Object
readonly
Returns the value of attribute pagination.
-
#runs ⇒ Object
readonly
Returns the value of attribute runs.
Instance Method Summary collapse
- #auto_paging_each(&block) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(data, fetch_page) ⇒ RunsPage
constructor
A new instance of RunsPage.
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
Constructor Details
#initialize(data, fetch_page) ⇒ RunsPage
Returns a new instance of RunsPage.
11 12 13 14 15 16 17 |
# File 'lib/riveter/page.rb', line 11 def initialize(data, fetch_page) data = data.is_a?(Hash) ? data : {} @runs = (data["runs"] || []).map { |item| RunListItem.new(item) } @pagination = Pagination.new(data["pagination"] || {}) @monitor_id = data["monitor_id"] @fetch_page = fetch_page end |
Instance Attribute Details
#monitor_id ⇒ Object (readonly)
Returns the value of attribute monitor_id.
9 10 11 |
# File 'lib/riveter/page.rb', line 9 def monitor_id @monitor_id end |
#pagination ⇒ Object (readonly)
Returns the value of attribute pagination.
9 10 11 |
# File 'lib/riveter/page.rb', line 9 def pagination @pagination end |
#runs ⇒ Object (readonly)
Returns the value of attribute runs.
9 10 11 |
# File 'lib/riveter/page.rb', line 9 def runs @runs end |
Instance Method Details
#auto_paging_each(&block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/riveter/page.rb', line 31 def auto_paging_each(&block) return enum_for(:auto_paging_each) unless block page = self loop do page.runs.each(&block) break unless page.next_page? page = page.next_page end end |
#each(&block) ⇒ Object
19 20 21 |
# File 'lib/riveter/page.rb', line 19 def each(&block) @runs.each(&block) end |
#next_page ⇒ Object
27 28 29 |
# File 'lib/riveter/page.rb', line 27 def next_page RunsPage.new(@fetch_page.call((pagination.page || 1) + 1), @fetch_page) end |
#next_page? ⇒ Boolean
23 24 25 |
# File 'lib/riveter/page.rb', line 23 def next_page? (pagination.page || 1) < (pagination.total_pages || 1) end |