Class: GreenButtonData::ModelCollection
- Inherits:
-
Object
- Object
- GreenButtonData::ModelCollection
- Includes:
- Enumerable
- Defined in:
- lib/green-button-data/model_collection.rb
Instance Method Summary collapse
- #<<(model) ⇒ Object
- #each ⇒ Object
- #find_by_id(id) ⇒ Object
-
#initialize ⇒ ModelCollection
constructor
A new instance of ModelCollection.
- #last ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ ModelCollection
Returns a new instance of ModelCollection.
5 6 7 |
# File 'lib/green-button-data/model_collection.rb', line 5 def initialize @models = [] end |
Instance Method Details
#<<(model) ⇒ Object
9 10 11 |
# File 'lib/green-button-data/model_collection.rb', line 9 def <<(model) @models << model end |
#each ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/green-button-data/model_collection.rb', line 13 def each return enum_for(:each) unless block_given? @models.each do |model| yield model end end |
#find_by_id(id) ⇒ Object
29 30 31 |
# File 'lib/green-button-data/model_collection.rb', line 29 def find_by_id(id) self.find {|model| model.id.to_s == id.to_s } end |
#last ⇒ Object
21 22 23 |
# File 'lib/green-button-data/model_collection.rb', line 21 def last @models.last end |
#size ⇒ Object
25 26 27 |
# File 'lib/green-button-data/model_collection.rb', line 25 def size @models.size end |