Class: Funk::Instruments::GraphViz
- Inherits:
-
Object
- Object
- Funk::Instruments::GraphViz
- Defined in:
- lib/funk/instruments/graph_viz.rb
Instance Method Summary collapse
- #after_call(fn, input, value) ⇒ Object
- #digraph ⇒ Object
-
#initialize ⇒ GraphViz
constructor
A new instance of GraphViz.
Constructor Details
#initialize ⇒ GraphViz
Returns a new instance of GraphViz.
4 5 6 |
# File 'lib/funk/instruments/graph_viz.rb', line 4 def initialize @dots = [] end |
Instance Method Details
#after_call(fn, input, value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/funk/instruments/graph_viz.rb', line 8 def after_call(fn, input, value) name = "node #{fn.name}" style = { "label" => "< #{fn.name} <br/> #{value.inspect} >", "shape" => fn.is_a?(InputFn) ? "circle" : "box", } node = name + "[" + style.map { |attr,val| "#{attr}=#{val}" }.join(" ") + "]" @dots << node fn.dependencies.each do |dep| edge = "#{dep} -> #{fn.name}" @dots << edge end end |
#digraph ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/funk/instruments/graph_viz.rb', line 23 def digraph digraph = [] digraph << "digraph {" digraph.concat(@dots) digraph << "}" digraph.join("\n") end |