Class: Hashematics::Graph
- Inherits:
-
Object
- Object
- Hashematics::Graph
- Extended by:
- Forwardable
- Defined in:
- lib/hashematics/graph.rb
Overview
Graph serves as the main point of entry for this system. Basic use:
-
Initialize a Graph by passing in an array of groups (tree structures)
-
Feed in objects into the graph using the #add method
-
Use the #groups, #records, and #objects methods to interact with the generated object graph.
Instance Attribute Summary collapse
-
#group_dictionary ⇒ Object
readonly
Returns the value of attribute group_dictionary.
-
#record_set ⇒ Object
readonly
Returns the value of attribute record_set.
Instance Method Summary collapse
- #add(enumerable) ⇒ Object
- #children ⇒ Object
- #data(name) ⇒ Object
-
#initialize(groups = []) ⇒ Graph
constructor
A new instance of Graph.
- #visit(name) ⇒ Object
Constructor Details
Instance Attribute Details
#group_dictionary ⇒ Object (readonly)
Returns the value of attribute group_dictionary.
19 20 21 |
# File 'lib/hashematics/graph.rb', line 19 def group_dictionary @group_dictionary end |
#record_set ⇒ Object (readonly)
Returns the value of attribute record_set.
19 20 21 |
# File 'lib/hashematics/graph.rb', line 19 def record_set @record_set end |
Instance Method Details
#add(enumerable) ⇒ Object
30 31 32 33 34 |
# File 'lib/hashematics/graph.rb', line 30 def add(enumerable) enumerable.each { |object| add_one(object) } self end |
#children ⇒ Object
36 37 38 |
# File 'lib/hashematics/graph.rb', line 36 def children group_dictionary.map(&:name) end |
#data(name) ⇒ Object
44 45 46 |
# File 'lib/hashematics/graph.rb', line 44 def data(name) visit(name).map { |v| v.data(true) } end |
#visit(name) ⇒ Object
40 41 42 |
# File 'lib/hashematics/graph.rb', line 40 def visit(name) group(name)&.visit || [] end |