ahnen/geanology.rb

32 lines
701 B
Ruby

class Node
attr_reader :style
attr_accessor :childs
def initialize(style)
@style = style
@childs = []
end
end
nodes = {}
f = File.open("ahnen.dot.txt","r")
f.each_line do |line|
case line
# Label1 -> Label1 [style...]
when /^\s*(\S+)\s*->\s*(\S+)\s*\[([^\]]+)\]/
parent, child, style = $1, $2, $3
if not nodes[child]
$stderr.puts("child not found '#{child}'")
elsif not nodes[parent]
$stderr.puts("parent not found '#{parent}'")
else
nodes[parent].childs << child
end
# Label [style...]
when /^\s*(\S+)\s+\[([^\]]+)\]/
node, style = $1, $2
nodes[node] = Node.new(style)
else
#print "ignore -> #{line}"
end
end