Class: XeroKiwi::Page
- Inherits:
-
Object
- Object
- XeroKiwi::Page
- Includes:
- Enumerable
- Defined in:
- lib/xero_kiwi/page.rb
Overview
A paginated list result from a Xero endpoint. Wraps the items with the pagination metadata Xero returns in the response envelope when ‘page=` is passed. Behaves like an Array for iteration and collection methods (Enumerable + `size` / `empty?` / `to_a`), so most callers can keep working with the value directly.
Callers that need raw Array behaviour (mutation, slicing, ‘JSON.dump`, `is_a?(Array)` checks) should call `.to_a`.
Instance Attribute Summary collapse
-
#item_count ⇒ Object
readonly
Returns the value of attribute item_count.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(items:, page: nil, page_size: nil, item_count: nil, total_count: nil) ⇒ Page
constructor
A new instance of Page.
- #inspect ⇒ Object
- #size ⇒ Object (also: #length)
- #to_a ⇒ Object
Constructor Details
#initialize(items:, page: nil, page_size: nil, item_count: nil, total_count: nil) ⇒ Page
Returns a new instance of Page.
17 18 19 20 21 22 23 |
# File 'lib/xero_kiwi/page.rb', line 17 def initialize(items:, page: nil, page_size: nil, item_count: nil, total_count: nil) @items = items @page = page @page_size = page_size @item_count = item_count @total_count = total_count end |
Instance Attribute Details
#item_count ⇒ Object (readonly)
Returns the value of attribute item_count.
15 16 17 |
# File 'lib/xero_kiwi/page.rb', line 15 def item_count @item_count end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
15 16 17 |
# File 'lib/xero_kiwi/page.rb', line 15 def items @items end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
15 16 17 |
# File 'lib/xero_kiwi/page.rb', line 15 def page @page end |
#page_size ⇒ Object (readonly)
Returns the value of attribute page_size.
15 16 17 |
# File 'lib/xero_kiwi/page.rb', line 15 def page_size @page_size end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
15 16 17 |
# File 'lib/xero_kiwi/page.rb', line 15 def total_count @total_count end |
Instance Method Details
#each(&block) ⇒ Object
25 26 27 28 29 |
# File 'lib/xero_kiwi/page.rb', line 25 def each(&block) return to_enum(:each) unless block @items.each(&block) end |
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/xero_kiwi/page.rb', line 36 def empty? @items.empty? end |
#inspect ⇒ Object
44 45 46 47 |
# File 'lib/xero_kiwi/page.rb', line 44 def inspect "#<#{self.class} items=#{size} page=#{page.inspect} " \ "page_size=#{page_size.inspect} item_count=#{item_count.inspect}>" end |
#size ⇒ Object Also known as: length
31 32 33 |
# File 'lib/xero_kiwi/page.rb', line 31 def size @items.size end |
#to_a ⇒ Object
40 41 42 |
# File 'lib/xero_kiwi/page.rb', line 40 def to_a @items.dup end |