module Graphviz
Nested
Definitions
def self.output(graph, path: nil, format: "pdf", dot: "dot")
Outputs the graph using the +dot+ executable.
Signature
-
option
options
String
:format ('pdf') The output format (e.g. pdf).
-
option
options
String
:path The output path, if not specified data is returned.
-
option
options
String
:dot ('dot') The +dot+ executable to use.
Implementation
def self.output(graph, path: nil, format: "pdf", dot: "dot")
output_format = format
if path
# Grab the output format from the file name:
if path =~ /\.(.*?)$/
output_format ||= $1
end
end
output, input = IO.pipe
pipeline = Process::Pipeline.(dot, "-T#{output_format}")
writer = Thread.new do
graph.dump_graph(input)
input.close
end
if path
pipeline.write(path, input: output)
else
return pipeline.read(input: output)
end
ensure
writer.join
end