Class: Bulk::AbstractCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bulk/abstract_collection.rb

Direct Known Subclasses

Collection, Collection::Errors

Instance Method Summary collapse

Constructor Details

#initializeAbstractCollection

Returns a new instance of AbstractCollection.



5
6
7
# File 'lib/bulk/abstract_collection.rb', line 5

def initialize
  @items = {}
end

Instance Method Details

#clearObject

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

Returns:

  • (Boolean)


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

#idsObject

Return items ids



46
47
48
# File 'lib/bulk/abstract_collection.rb', line 46

def ids
  items.keys
end

#lengthObject

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