Class: MARS::Rendering::Graph::Builder
- Inherits:
-
Object
- Object
- MARS::Rendering::Graph::Builder
- Defined in:
- lib/mars/rendering/graph/builder.rb
Instance Attribute Summary collapse
-
#adjacency ⇒ Object
readonly
Returns the value of attribute adjacency.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#subgraphs ⇒ Object
readonly
Returns the value of attribute subgraphs.
Instance Method Summary collapse
- #add_edge(from, to, value = nil) ⇒ Object
- #add_node(id, value, type) ⇒ Object
- #add_node_to_subgraph(id, node_id) ⇒ Object
- #add_subgraph(id, name) ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 13 |
# File 'lib/mars/rendering/graph/builder.rb', line 9 def initialize @adjacency = Hash.new { |h, k| h[k] = [] } @nodes = {} @subgraphs = {} end |
Instance Attribute Details
#adjacency ⇒ Object (readonly)
Returns the value of attribute adjacency.
7 8 9 |
# File 'lib/mars/rendering/graph/builder.rb', line 7 def adjacency @adjacency end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
7 8 9 |
# File 'lib/mars/rendering/graph/builder.rb', line 7 def nodes @nodes end |
#subgraphs ⇒ Object (readonly)
Returns the value of attribute subgraphs.
7 8 9 |
# File 'lib/mars/rendering/graph/builder.rb', line 7 def subgraphs @subgraphs end |
Instance Method Details
#add_edge(from, to, value = nil) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/mars/rendering/graph/builder.rb', line 15 def add_edge(from, to, value = nil) return unless from && to # can we avoid visiting the node twice instead? adjacency[from] << [to, value] unless adjacency[from].include?([to, value]) adjacency[to] = [] unless adjacency[to] end |
#add_node(id, value, type) ⇒ Object
23 24 25 26 27 |
# File 'lib/mars/rendering/graph/builder.rb', line 23 def add_node(id, value, type) return if nodes.key?(id) nodes[id] = Node.new(id, value, type) end |
#add_node_to_subgraph(id, node_id) ⇒ Object
35 36 37 38 39 |
# File 'lib/mars/rendering/graph/builder.rb', line 35 def add_node_to_subgraph(id, node_id) return if subgraphs[id]&.nodes&.include?(node_id) subgraphs[id].nodes << node_id end |