Sha256: 0287df793360732fb1abcb31080c40b59ee45d1b1c825514f020c1046575b8b2

Contents?: true

Size: 710 Bytes

Versions: 2

Compression:

Stored size: 710 Bytes

Contents

module Furnace
  class Graphviz
    def initialize
      @code = "digraph {\n"
      @code << "node [labeljust=l,nojustify=true,fontname=monospace];"
      @code << "rankdir=TB;"

      yield self

      @code << "}"
    end

    def node(name, content)
      content.gsub!("&", "&amp;")
      content.gsub!(">", "&gt;")
      content.gsub!("<", "&lt;")
      content = content.lines.map { |l| %Q{<tr><td align="left">#{l}</td></tr>} }.join

      @code << %Q{#{name.inspect} [shape=box,label=<<table border="0">#{content}</table>>];\n}
    end

    def edge(from, to, label="")
      @code << %Q{#{from.inspect} -> #{to.inspect} [label=#{label.inspect}];\n}
    end

    def to_s
      @code
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
furnace-0.0.2 lib/furnace/graphviz.rb
furnace-0.0.1 lib/furnace/graphviz.rb