Class: Arke::Resource::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, array) ⇒ Collection

Returns a new instance of Collection.



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

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
  @parent = parent
  @array = array.collect { |item| @parent.new(item) }
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

Instance Method Details

#[](key) ⇒ Object



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

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

#each(&block) ⇒ Object



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

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

#firstObject



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

def first
  self[0]
end

#inspectObject



36
37
38
# File 'lib/arke/resource/collection.rb', line 36

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

#lastObject



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

def last
  self[-1]
end

#lengthObject



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

def length
  @array.length
end