Class: Arke::Resource::Collection
- Inherits:
-
Object
- Object
- Arke::Resource::Collection
- Includes:
- Enumerable
- Defined in:
- lib/arke/resource/collection.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
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.
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
#parent ⇒ Object (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 |
#first ⇒ Object
24 25 26 |
# File 'lib/arke/resource/collection.rb', line 24 def first self[0] end |
#inspect ⇒ Object
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 |
#last ⇒ Object
28 29 30 |
# File 'lib/arke/resource/collection.rb', line 28 def last self[-1] end |
#length ⇒ Object
32 33 34 |
# File 'lib/arke/resource/collection.rb', line 32 def length @array.length end |