Class: Zipmark::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, iterator_class) ⇒ Collection

Returns a new instance of Collection.



7
8
9
10
# File 'lib/zipmark/collection.rb', line 7

def initialize(resource, iterator_class)
  fetched_resource = resource.client.get(resource.href).body
  @iterator = iterator_class.new(fetched_resource, :resource_name => resource.rel, :client => resource.client)
end

Instance Attribute Details

#iteratorObject

Returns the value of attribute iterator.



5
6
7
# File 'lib/zipmark/collection.rb', line 5

def iterator
  @iterator
end

Instance Method Details

#eachObject



20
21
22
23
24
25
# File 'lib/zipmark/collection.rb', line 20

def each
  # Wrapping in the being block ensures that the current_item is yielded once before next_item is called
  begin
    yield iterator.current_item
  end while iterator.next_item
end

#itemsObject



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

def items
  iterator.items
end

#lengthObject



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

def length
  iterator.total_items
end