Class: Seedable::ObjectTracker
- Inherits:
-
Object
- Object
- Seedable::ObjectTracker
- Defined in:
- lib/seedable/object_tracker.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#graph ⇒ Object
Returns the value of attribute graph.
Instance Method Summary collapse
-
#add(object) ⇒ Object
Add this object to the object tracker.
-
#contains?(object) ⇒ Boolean
Determine if the object tracker has already picked this object up.
-
#initialize ⇒ ObjectTracker
constructor
Create a new instance of the object tracker.
-
#to_s ⇒ Object
Display the object tracker in yaml for easy viewing.
Constructor Details
#initialize ⇒ ObjectTracker
Create a new instance of the object tracker.
10 11 12 |
# File 'lib/seedable/object_tracker.rb', line 10 def initialize @graph = {} end |
Instance Attribute Details
#graph ⇒ Object
Returns the value of attribute graph.
6 7 8 |
# File 'lib/seedable/object_tracker.rb', line 6 def graph @graph end |
Instance Method Details
#add(object) ⇒ Object
Add this object to the object tracker.
24 25 26 27 28 |
# File 'lib/seedable/object_tracker.rb', line 24 def add(object) key, id = to_key_and_id(object) @graph[key] ? @graph[key] << id : @graph[key] = [id] end |
#contains?(object) ⇒ Boolean
Determine if the object tracker has already picked this object up.
16 17 18 19 20 |
# File 'lib/seedable/object_tracker.rb', line 16 def contains?(object) key, id = to_key_and_id(object) @graph[key].is_a?(Enumerable) ? @graph[key].include?(id) : @graph[key] end |
#to_s ⇒ Object
Display the object tracker in yaml for easy viewing.
32 33 34 |
# File 'lib/seedable/object_tracker.rb', line 32 def to_s @graph.to_yaml end |