Module: Graphviz

Defined in:
lib/graphviz.rb,
lib/graphviz/graph.rb,
lib/graphviz/version.rb

Defined Under Namespace

Classes: Edge, EdgeNode, Graph, Node, OutputError

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.output(graph, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/graphviz.rb', line 30

def self.output(graph, options = {})
	text = graph.to_dot
	
	output_format = options[:format]
	
	if options[:path]
		# Grab the output format from the file name:
		if options[:path] =~ /\.(.*?)$/
			output_format ||= $1
		end
		
		output_file = File.open(options[:path], "w")
	else
		output_file = IO.pipe
	end
	
	RExec::Task.open(["dot", "-T#{output_format}"], :out => output_file) do |task|
		task.input.puts(graph.to_dot)
		task.input.close
		
		status = task.wait
		
		if status != 0
			raise OutputError.new(task.error.read)
		end
		
		# Did we use a local pipe for output?
		if Array === output_file
			return task.output.read
		end
	end
end