Class: Pastvu::Collection

Inherits:
BasicResponse show all
Includes:
Enumerable
Defined in:
lib/pastvu/collection.rb

Instance Attribute Summary

Attributes inherited from BasicResponse

#hash, #json

Instance Method Summary collapse

Methods inherited from BasicResponse

#to_hash, #to_json

Constructor Details

#initialize(attr) ⇒ Collection

Returns a new instance of Collection.



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

def initialize(attr)
  attr.instance_of?(Hash) ? @hash = attr : super
end

Instance Method Details

#eachObject



9
10
11
12
13
14
15
16
17
# File 'lib/pastvu/collection.rb', line 9

def each
  return to_enum(:each) unless block_given?

  @hash ||= self.to_hash

  reduce_hash.each do |model_hash|
    yield @model.new model_hash
  end
end