Class: Rexpense::Entities::Collection
- 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.
Direct Known Subclasses
ActivityCollection, AdvancementCollection, AttachmentCollection, CommentCollection, ExpenseCollection, MembershipCollection, OrganizationCollection, PreExpenseCollection, ReimbursementCollection, TagCollection, UserCollection, WebhookCollection
Constant Summary collapse
- PAGE_REGEX =
/page=(\d+)/
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #first_page ⇒ Object
-
#initialize(response) ⇒ Collection
constructor
A new instance of Collection.
- #last_page ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
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
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
11 12 13 |
# File 'lib/rexpense/entities/collection.rb', line 11 def collection @collection end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
11 12 13 |
# File 'lib/rexpense/entities/collection.rb', line 11 def headers @headers end |
#response ⇒ Object (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
#build ⇒ Object
27 28 29 30 |
# File 'lib/rexpense/entities/collection.rb', line 27 def build build_collection self end |
#first_page ⇒ Object
44 45 46 |
# File 'lib/rexpense/entities/collection.rb', line 44 def first_page page_for(:first) end |
#last_page ⇒ Object
36 37 38 |
# File 'lib/rexpense/entities/collection.rb', line 36 def last_page page_for(:last) end |
#next_page ⇒ Object
32 33 34 |
# File 'lib/rexpense/entities/collection.rb', line 32 def next_page page_for(:next) end |
#previous_page ⇒ Object
40 41 42 |
# File 'lib/rexpense/entities/collection.rb', line 40 def previous_page page_for(:prev) end |