first
This commit is contained in:
parent
98b613b9b8
commit
d7da41e38d
|
@ -0,0 +1,31 @@
|
|||
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
|
Loading…
Reference in New Issue