Class: Rexpense::Entities::Collection

Inherits:
Base
  • Object
show all
Defined in:
lib/rexpense/entities/collection.rb

Overview

A wrapper to Rexpense collection returns from API. This wrapper represents a collection and it’s responsible for processing pagination information as well.

Constant Summary collapse

PAGE_REGEX =
/page=(\d+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Collection

Returns a new instance of Collection.



13
14
15
16
17
18
19
20
21
# File 'lib/rexpense/entities/collection.rb', line 13

def initialize(response)
  @response = response
  @collection = []
  @headers = begin
               response.headers["Link"].split(",")
             rescue
               []
             end
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



11
12
13
# File 'lib/rexpense/entities/collection.rb', line 11

def collection
  @collection
end

#headersObject (readonly)

Returns the value of attribute headers.



11
12
13
# File 'lib/rexpense/entities/collection.rb', line 11

def headers
  @headers
end

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/rexpense/entities/collection.rb', line 11

def response
  @response
end

Class Method Details

.build(response) ⇒ Object



23
24
25
# File 'lib/rexpense/entities/collection.rb', line 23

def self.build(response)
  new(response).build
end

Instance Method Details

#buildObject



27
28
29
30
# File 'lib/rexpense/entities/collection.rb', line 27

def build
  build_collection
  self
end

#first_pageObject



44
45
46
# File 'lib/rexpense/entities/collection.rb', line 44

def first_page
  page_for(:first)
end

#last_pageObject



36
37
38
# File 'lib/rexpense/entities/collection.rb', line 36

def last_page
  page_for(:last)
end

#next_pageObject



32
33
34
# File 'lib/rexpense/entities/collection.rb', line 32

def next_page
  page_for(:next)
end

#previous_pageObject



40
41
42
# File 'lib/rexpense/entities/collection.rb', line 40

def previous_page
  page_for(:prev)
end