Class: AhoSdk::Page
Overview
Paginated response with lazy iteration support
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
Instance Method Summary collapse
-
#current_page ⇒ Integer
Current page number.
-
#each {|Hash| ... } ⇒ Enumerator
Iterate through all items across all pages (lazy loading).
-
#initialize(data:, meta:, fetch_next:) ⇒ Page
constructor
A new instance of Page.
-
#last_page? ⇒ Boolean
True if this is the last page.
-
#next_page ⇒ Page?
Fetch the next page.
-
#per_page ⇒ Integer
Number of items per page.
-
#total_count ⇒ Integer
Total number of items across all pages.
-
#total_pages ⇒ Integer
Total number of pages.
Constructor Details
#initialize(data:, meta:, fetch_next:) ⇒ Page
Returns a new instance of Page.
29 30 31 32 33 |
# File 'lib/aho_sdk/page.rb', line 29 def initialize(data:, meta:, fetch_next:) @data = data @meta = @fetch_next = fetch_next end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
24 25 26 |
# File 'lib/aho_sdk/page.rb', line 24 def data @data end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
24 25 26 |
# File 'lib/aho_sdk/page.rb', line 24 def @meta end |
Instance Method Details
#current_page ⇒ Integer
Returns Current page number.
63 64 65 |
# File 'lib/aho_sdk/page.rb', line 63 def current_page [:current_page] end |
#each {|Hash| ... } ⇒ Enumerator
Iterate through all items across all pages (lazy loading)
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aho_sdk/page.rb', line 38 def each(&block) return enum_for(:each) unless block_given? page = self loop do page.data.each(&block) page = page.next_page break if page.nil? end end |
#last_page? ⇒ Boolean
Returns true if this is the last page.
58 59 60 |
# File 'lib/aho_sdk/page.rb', line 58 def last_page? [:current_page] >= [:total_pages] end |
#next_page ⇒ Page?
Fetch the next page
51 52 53 54 55 |
# File 'lib/aho_sdk/page.rb', line 51 def next_page return nil if last_page? @fetch_next.call([:current_page] + 1) end |
#per_page ⇒ Integer
Returns Number of items per page.
78 79 80 |
# File 'lib/aho_sdk/page.rb', line 78 def per_page [:per_page] end |
#total_count ⇒ Integer
Returns Total number of items across all pages.
73 74 75 |
# File 'lib/aho_sdk/page.rb', line 73 def total_count [:total_count] end |
#total_pages ⇒ Integer
Returns Total number of pages.
68 69 70 |
# File 'lib/aho_sdk/page.rb', line 68 def total_pages [:total_pages] end |