Class: Bulk::AbstractCollection
- Inherits:
-
Object
- Object
- Bulk::AbstractCollection
- Includes:
- Enumerable
- Defined in:
- lib/bulk/abstract_collection.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#clear ⇒ Object
Clear records on collection.
-
#delete(id) ⇒ Object
Remove record from collection.
-
#empty? ⇒ Boolean
Checks if collection is empty.
-
#get(id) ⇒ Object
(also: #exists?)
Get record with given id.
-
#ids ⇒ Object
Return items ids.
-
#initialize ⇒ AbstractCollection
constructor
A new instance of AbstractCollection.
-
#length ⇒ Object
Get the collection length.
-
#set(id, item) ⇒ Object
Set record for a given id.
Constructor Details
#initialize ⇒ AbstractCollection
Returns a new instance of AbstractCollection.
5 6 7 |
# File 'lib/bulk/abstract_collection.rb', line 5 def initialize @items = {} end |
Instance Method Details
#clear ⇒ Object
Clear records on collection
10 11 12 |
# File 'lib/bulk/abstract_collection.rb', line 10 def clear items.clear end |
#delete(id) ⇒ Object
Remove record from collection
26 27 28 |
# File 'lib/bulk/abstract_collection.rb', line 26 def delete(id) items.delete(id.to_s) end |
#empty? ⇒ Boolean
Checks if collection is empty
41 42 43 |
# File 'lib/bulk/abstract_collection.rb', line 41 def empty? items.empty? end |
#get(id) ⇒ Object Also known as: exists?
Get record with given id
15 16 17 |
# File 'lib/bulk/abstract_collection.rb', line 15 def get(id) items[id.to_s] end |
#ids ⇒ Object
Return items ids
46 47 48 |
# File 'lib/bulk/abstract_collection.rb', line 46 def ids items.keys end |
#length ⇒ Object
Get the collection length
31 32 33 |
# File 'lib/bulk/abstract_collection.rb', line 31 def length items.length end |
#set(id, item) ⇒ Object
Set record for a given id
21 22 23 |
# File 'lib/bulk/abstract_collection.rb', line 21 def set(id, item) items[id.to_s] = item end |