Class: FluvPay::Resources::PageList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fluvpay/resources/list_objects.rb

Overview

Página baseada em page/per_page (usada por charges.list e transactions.list).

Expõe #data (os itens) e os metadados page, per_page, total, has_next e has_prev, exatamente como o backend retorna. Também é iterável: page.each { |item| … }.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ PageList

Returns a new instance of PageList.



17
18
19
20
21
22
23
24
25
# File 'lib/fluvpay/resources/list_objects.rb', line 17

def initialize(payload)
  payload ||= {}
  @data = payload["data"] || []
  @page = payload["page"]
  @per_page = payload["per_page"]
  @total = payload["total"]
  @has_next = payload["has_next"]
  @has_prev = payload["has_prev"]
end

Instance Attribute Details

#dataArray<Hash> (readonly)

Returns itens da página.

Returns:

  • (Array<Hash>)

    itens da página.



14
15
16
# File 'lib/fluvpay/resources/list_objects.rb', line 14

def data
  @data
end

#pageObject (readonly)

Returns the value of attribute page.



15
16
17
# File 'lib/fluvpay/resources/list_objects.rb', line 15

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



15
16
17
# File 'lib/fluvpay/resources/list_objects.rb', line 15

def per_page
  @per_page
end

#totalObject (readonly)

Returns the value of attribute total.



15
16
17
# File 'lib/fluvpay/resources/list_objects.rb', line 15

def total
  @total
end

Instance Method Details

#each(&block) ⇒ Object



37
38
39
# File 'lib/fluvpay/resources/list_objects.rb', line 37

def each(&block)
  @data.each(&block)
end

#has_next?Boolean

Returns true se existe próxima página.

Returns:

  • (Boolean)

    true se existe próxima página.



28
29
30
# File 'lib/fluvpay/resources/list_objects.rb', line 28

def has_next?
  @has_next ? true : false
end

#has_prev?Boolean

Returns true se existe página anterior.

Returns:

  • (Boolean)

    true se existe página anterior.



33
34
35
# File 'lib/fluvpay/resources/list_objects.rb', line 33

def has_prev?
  @has_prev ? true : false
end