Class: Arke::Resource::Collection
- Inherits:
-
Object
- Object
- Arke::Resource::Collection
- Includes:
- Enumerable
- Defined in:
- lib/arke/resource/collection.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each(&block) ⇒ Object
- #first ⇒ Object
-
#initialize(parent, array) ⇒ Collection
constructor
A new instance of Collection.
- #inspect ⇒ Object
- #last ⇒ Object
- #length ⇒ Object
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 |
#first ⇒ Object
20 21 22 |
# File 'lib/arke/resource/collection.rb', line 20 def first self[0] end |
#inspect ⇒ Object
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 |
#last ⇒ Object
24 25 26 |
# File 'lib/arke/resource/collection.rb', line 24 def last self[-1] end |
#length ⇒ Object
28 29 30 |
# File 'lib/arke/resource/collection.rb', line 28 def length @array.length end |