Class: Graph
- Inherits:
-
Object
- Object
- Graph
- Defined in:
- lib/graph.rb
Instance Attribute Summary collapse
-
#underlying ⇒ Object
readonly
Returns the value of attribute underlying.
Instance Method Summary collapse
- #add_edge(from, to, opts) ⇒ Object
- #add_node(name, opts) ⇒ Object
- #filter(source, destination) ⇒ Object
-
#initialize(config, underlying = RGL::DirectedAdjacencyGraph.new) ⇒ Graph
constructor
A new instance of Graph.
- #log(msg) ⇒ Object
- #output(renderer) ⇒ Object
Constructor Details
#initialize(config, underlying = RGL::DirectedAdjacencyGraph.new) ⇒ Graph
Returns a new instance of Graph.
6 7 8 9 10 11 |
# File 'lib/graph.rb', line 6 def initialize(config, =RGL::DirectedAdjacencyGraph.new) @config = config @underlying = @edge_properties = {} @node_properties = {} end |
Instance Attribute Details
#underlying ⇒ Object (readonly)
Returns the value of attribute underlying.
4 5 6 |
# File 'lib/graph.rb', line 4 def @underlying end |
Instance Method Details
#add_edge(from, to, opts) ⇒ Object
19 20 21 22 23 |
# File 'lib/graph.rb', line 19 def add_edge(from, to, opts) log("edge: #{from} -> #{to}") @underlying.add_edge(from, to) @edge_properties[[from, to]] = opts end |
#add_node(name, opts) ⇒ Object
13 14 15 16 17 |
# File 'lib/graph.rb', line 13 def add_node(name, opts) log("node: #{name}, opts: #{opts}") @underlying.add_vertex(name) @node_properties[name] = opts end |
#filter(source, destination) ⇒ Object
25 26 27 |
# File 'lib/graph.rb', line 25 def filter(source, destination) @underlying = GraphFilter.new().filter(source, destination) end |
#log(msg) ⇒ Object
37 38 39 |
# File 'lib/graph.rb', line 37 def log(msg) puts msg if @config.debug? end |
#output(renderer) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/graph.rb', line 29 def output(renderer) @underlying.each_vertex { |v| renderer.add_node(v, @node_properties[v] || {}) } @underlying.each_edge { |u, v| renderer.add_edge(u, v, opts(u, v)) } renderer.output end |