Class: GoCardless::Page

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gocardless/page.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource_class, data, links) ⇒ Page

Returns a new instance of Page.


5
6
7
8
9
# File 'lib/gocardless/page.rb', line 5

def initialize(resource_class, data, links)
  @resource_class = resource_class
  @data = data
  @links = links
end

Instance Method Details

#each(&block) ⇒ Object

Yield each of the items in the page as instances of the resource class


37
38
39
40
41
# File 'lib/gocardless/page.rb', line 37

def each(&block)
  @data.each do |attrs|
    yield @resource_class.new(attrs)
  end
end

#first_pageObject

The first page number, nil if this is the first page


22
23
24
# File 'lib/gocardless/page.rb', line 22

def first_page
  @links['first']
end

#has_next?Boolean

Used for page iteration

Returns:

  • (Boolean)

32
33
34
# File 'lib/gocardless/page.rb', line 32

def has_next?
  !!@links['next']
end

#last_pageObject

The last page number, nil if this is the last page


27
28
29
# File 'lib/gocardless/page.rb', line 27

def last_page
  @links['last']
end

#next_pageObject

The next page number, nil if there is no next page


12
13
14
# File 'lib/gocardless/page.rb', line 12

def next_page
  @links['next']
end

#previous_pageObject

The previous page number, nil if there is no previous page


17
18
19
# File 'lib/gocardless/page.rb', line 17

def previous_page
  @links['previous']
end