Class: Arke::Resource::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/arke/resource/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent, array) ⇒ Collection

Returns a new instance of Collection.



6
7
8
9
10
# File 'lib/arke/resource/collection.rb', line 6

def initialize(parent, array)
  raise Errors::UnexpectedResponse.
          new("#all expected to receive an Array from the resource, instead a #{array.class} was received.") unless array.is_a? Array
  @array = array.collect { |item| parent.new(item) }
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/arke/resource/collection.rb', line 16

def [](key)
  @array[key]
end

#each(&block) ⇒ Object



12
13
14
# File 'lib/arke/resource/collection.rb', line 12

def each(&block)
  @array.each &block
end

#firstObject



20
21
22
# File 'lib/arke/resource/collection.rb', line 20

def first
  self[0]
end

#inspectObject



32
33
34
# File 'lib/arke/resource/collection.rb', line 32

def inspect
  "#<#{self.class.name}:0x%08x record_count: #{self.length}>" % (object_id * 2)
end

#lastObject



24
25
26
# File 'lib/arke/resource/collection.rb', line 24

def last
  self[-1]
end

#lengthObject



28
29
30
# File 'lib/arke/resource/collection.rb', line 28

def length
  @array.length
end