Class: Pin::CollectionResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/pin-payments/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, per_page, page_count, current_page) ⇒ CollectionResponse

Returns a new instance of CollectionResponse.



5
6
7
8
9
10
# File 'lib/pin-payments/response.rb', line 5

def initialize(collection, per_page, page_count, current_page)
  @collection = collection
  @page_count = page_count
  @per_page = per_page
  @page = current_page
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/pin-payments/response.rb', line 28

def method_missing(meth, *args, &block)
  if collection.respond_to?(meth)
    collection.send(meth, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



3
4
5
# File 'lib/pin-payments/response.rb', line 3

def collection
  @collection
end

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/pin-payments/response.rb', line 3

def page
  @page
end

#page_countObject (readonly)

Returns the value of attribute page_count.



3
4
5
# File 'lib/pin-payments/response.rb', line 3

def page_count
  @page_count
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



3
4
5
# File 'lib/pin-payments/response.rb', line 3

def per_page
  @per_page
end

Instance Method Details

#first_page?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/pin-payments/response.rb', line 12

def first_page?
  @page == 1
end

#last_page?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/pin-payments/response.rb', line 16

def last_page?
  @page == @page_count
end

#next_page?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/pin-payments/response.rb', line 20

def next_page?
  @page_count > 1 && !last_page?
end

#previous_page?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/pin-payments/response.rb', line 24

def previous_page?
  @page_count > 1 && !first_page?
end