Sha256: 1cbcbf0cd76428c3d8709924fe415e7725bb097462a733ce7271cd4b45446487
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
module Braintree class PagedCollection include BaseModule include Enumerable attr_reader :current_page_number, :items, :next_page_number, :page_size, :previous_page_number, :total_items def initialize(attributes, &block) # :nodoc: set_instance_variables_from_hash attributes @paging_block = block end # Returns the item from the current page at the given +index+. def [](index) @items[index] end # Yields each item on the current page. def each(&block) @items.each(&block) end # Returns the first item from the current page. def first @items.first end # Returns true if the page is the last page. False otherwise. def last_page? current_page_number == total_pages end # Retrieves the next page of records. def next_page if last_page? return nil end @paging_block.call(next_page_number) end # The next page number. Returns +nil+ if on the last page. def next_page_number last_page? ? nil : current_page_number + 1 end # Returns the total number of pages. def total_pages total = total_items / page_size if total_items % page_size != 0 total += 1 end total end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
braintree-1.0.1 | lib/braintree/paged_collection.rb |
braintree-1.0.0 | lib/braintree/paged_collection.rb |