Class: Archsight::Graphvis
- Inherits:
-
Object
- Object
- Archsight::Graphvis
- Defined in:
- lib/archsight/graph.rb
Overview
Graphvis implements a graphviz abstraction
Instance Method Summary collapse
- #defaults(type, attrs = {}) ⇒ Object
- #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.
8 9 10 11 |
# File 'lib/archsight/graph.rb', line 8 def initialize(name, attrs = {}) @name = name @attrs = { rankdir: :LR }.merge(attrs) end |
Instance Method Details
#defaults(type, attrs = {}) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/archsight/graph.rb', line 59 def defaults(type, attrs = {}) @file.print " #{type} [" attrs.each do |k, v| @file.print " #{k.to_s.inspect} = #{value v}" end @file.puts " ];" end |
#draw_dot ⇒ Object
13 14 15 16 17 |
# File 'lib/archsight/graph.rb', line 13 def draw_dot(&) f = StringIO.new render(f, &) f.string end |
#edge(node_a, node_b, attrs = {}) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/archsight/graph.rb', line 37 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
29 30 31 32 33 34 35 |
# File 'lib/archsight/graph.rb', line 29 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
19 20 21 22 23 24 25 26 27 |
# File 'lib/archsight/graph.rb', line 19 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
67 68 69 70 71 |
# File 'lib/archsight/graph.rb', line 67 def same_rank @file.puts " { rank = same; " yield(self) @file.puts " }" end |
#subgraph(name, attrs) {|_self| ... } ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/archsight/graph.rb', line 45 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
54 55 56 57 |
# File 'lib/archsight/graph.rb', line 54 def value(val) val = val.to_s val =~ /^<.*>$/ ? "<#{val}>" : val.inspect end |