Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dot
- def initialize
- @graph = [[]]
- end
- def __dot_graph &block
- instance_eval &block
- end
- # TODO: make this work
- def self.const_missing name, *params, &block
- method_missing(name, *params, &block)
- end
- def method_missing name, *params, &block
- unless (@graph.last[-2,2].any?{|e| [:>, :<].include? e} rescue true)
- tmp = @graph.last
- @graph.delete tmp
- new = tmp.last
- tmp = tmp[0..-2]
- @graph << tmp
- @graph << [new]
- end
- @graph.last << name
- return self
- end
- def > *params
- @graph.last.insert(-2, :>)
- return self
- end
- def < *params
- @graph.last.insert(-2, :>)
- return self
- end
- def __dot_export file = 'out.dot'
- File.open(file, 'w+') do |f|
- __dot_to_s.split("\n").each do |line|
- f.puts line
- end
- end
- end
- def __dot_import file
- File.readlines(file).each do |line|
- instance_eval line
- end
- end
- def __dot_to_s
- p @graph
- s = %{
- digraph A {
- #{@graph.map{|s| s.join(' ').gsub('>', '->')}.join(";\n ")}
- }
- }
- puts s
- s
- end
- end
- ARGV.each do |file|
- base = File.basename(file, '.rdot')
- dot = Dot.new
- dot.__dot_import file
- dot.__dot_export "#{base}.dot"
- out = `dot #{base}.dot -Tps`
- File.open("#{base}.ps", 'w+') do |file|
- out.each_line do |line|
- file.puts line
- end
- end
- system('ps2pdf', "#{base}.ps", "#{base}.pdf")
- end
Add Comment
Please, Sign In to add comment