Class: Archsight::Graphvis
- Inherits:
-
Object
- Object
- Archsight::Graphvis
- Defined in:
- lib/archsight/graph.rb
Overview
Graphvis implements a graphviz abstraction
Instance Method Summary collapse
- #draw_dot ⇒ Object
- #edge(node_a, node_b, attrs = {}) ⇒ Object
-
#initialize(name, attrs = {}) ⇒ Graphvis
constructor
A new instance of Graphvis.
- #node(name, attrs = {}) ⇒ Object
- #render(file) {|_self| ... } ⇒ Object
- #same_rank {|_self| ... } ⇒ Object
- #subgraph(name, attrs) {|_self| ... } ⇒ Object
- #value(val) ⇒ Object
Constructor Details
#initialize(name, attrs = {}) ⇒ Graphvis
Returns a new instance of Graphvis.
6 7 8 9 |
# File 'lib/archsight/graph.rb', line 6 def initialize(name, attrs = {}) @name = name @attrs = { rankdir: :LR }.merge(attrs) end |
Instance Method Details
#draw_dot ⇒ Object
11 12 13 14 15 |
# File 'lib/archsight/graph.rb', line 11 def draw_dot(&) f = StringIO.new render(f, &) f.string end |
#edge(node_a, node_b, attrs = {}) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/archsight/graph.rb', line 35 def edge(node_a, node_b, attrs = {}) @file.print " #{node_a.inspect} -> #{node_b.inspect} [" attrs.each do |k, v| @file.print " #{k.to_s.inspect} = #{value v}" end @file.puts " ];" end |
#node(name, attrs = {}) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/archsight/graph.rb', line 27 def node(name, attrs = {}) @file.print " #{name.inspect} [" attrs.each do |k, v| @file.print " #{k.to_s.inspect} = #{value v}" end @file.puts " ];" end |
#render(file) {|_self| ... } ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/archsight/graph.rb', line 17 def render(file) @file = file file.puts "digraph G {" @attrs.each do |k, v| @file.puts " #{k.to_s.inspect} = #{value v};" end yield(self) file.puts "}" end |
#same_rank {|_self| ... } ⇒ Object
57 58 59 60 61 |
# File 'lib/archsight/graph.rb', line 57 def same_rank @file.puts " { rank = same; " yield(self) @file.puts " }" end |
#subgraph(name, attrs) {|_self| ... } ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/archsight/graph.rb', line 43 def subgraph(name, attrs) @file.puts " subgraph #{name.inspect} {" attrs.each do |k, v| @file.puts " #{k.to_s.inspect} = #{value v};" end yield(self) @file.puts " }" end |
#value(val) ⇒ Object
52 53 54 55 |
# File 'lib/archsight/graph.rb', line 52 def value(val) val = val.to_s val =~ /^<.*>$/ ? "<#{val}>" : val.inspect end |