Class: Emites::Entities::Collection

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/emites/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.



12
13
14
15
16
17
# File 'lib/emites/entities/collection.rb', line 12

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.



9
10
11
# File 'lib/emites/entities/collection.rb', line 9

def total
  @total
end

Class Method Details

.build(response, entity_class) ⇒ Object



19
20
21
# File 'lib/emites/entities/collection.rb', line 19

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

Instance Method Details

#buildObject



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

def build
  build_collection
  self
end

#next_pageObject



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

def next_page
  page_for('next')
end

#previous_pageObject



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

def previous_page
  page_for('previous')
end

#to_aObject



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

def to_a
  @collection.clone
end