Class: PassaporteWeb::Entities::Collection

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/passaporte_web/entities/collection.rb

Constant Summary collapse

PAGE_REGEX =
/page=(\d+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, entity_class) ⇒ Collection

Returns a new instance of Collection.


9
10
11
12
13
14
# File 'lib/passaporte_web/entities/collection.rb', line 9

def initialize(response, entity_class)
 @response = response
 @entity_class = entity_class
 @total = parsed_body['count'].to_i
 @collection = []
end

Instance Attribute Details

#totalObject (readonly)

Returns the value of attribute total


6
7
8
# File 'lib/passaporte_web/entities/collection.rb', line 6

def total
  @total
end

Class Method Details

.build(response, entity_class) ⇒ Object


16
17
18
# File 'lib/passaporte_web/entities/collection.rb', line 16

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

Instance Method Details

#buildObject


20
21
22
23
# File 'lib/passaporte_web/entities/collection.rb', line 20

def build
  build_collection
  self
end

#next_pageObject


25
26
27
# File 'lib/passaporte_web/entities/collection.rb', line 25

def next_page
  page_for('next')
end

#previous_pageObject


29
30
31
# File 'lib/passaporte_web/entities/collection.rb', line 29

def previous_page
  page_for('previous')
end

#to_aObject


33
34
35
# File 'lib/passaporte_web/entities/collection.rb', line 33

def to_a
  @collection.clone
end