require 'rubygems'
require 'graphviz'
class GraphViz
class FamilyTree
class Person
def initialize( graph, tree, generation, id ) @graph = graph
@node = @graph.add_nodes( id )
@node["shape"] = "box"
@tree = tree
@generation = generation
@x, @y = 0, 0
@sibling = nil
end
def id
@node.id
end
def name
@node.label || @node.id
end
def sibling
@sibling
end
def sibling=(x)
@sibling=x
end
def couples @couples
end
def node @node
end
def is_a_man( name )
@node["label"] = name
@node["color"] = "blue"
end
def is_a_boy( name )
is_a_man( name )
end
def is_a_woman( name )
@node["label"] = name
@node["color"] = "pink"
end
def is_a_girl( name )
is_a_woman( name )
end
def is_maried_with( x )
node = @graph.add_nodes( "#{@node.id}And#{x.node.id}" )
node["shape"] = "point"
@graph.add_edges( @node, node, "dir" => "none" )
@graph.add_edges( node, x.node, "dir" => "none" )
@tree.add_couple( self, x, node )
end
def is_divorced_with( x )
node = @graph.add_nodes( "#{@node.id}And#{x.node.id}" )
node["shape"] = "point"
node["color"] = "red"
@graph.add_edges( @node, node, "dir" => "none", "color" => "red" )
@graph.add_edges( node, x.node, "dir" => "none", "color" => "red" )
@tree.add_couple( self, x, node )
end
def is_widower_of( x ) node = @graph.add_nodes( "#{@node.id}And#{x.node.id}" )
node["shape"] = "point"
node["color"] = "green"
@graph.add_edges( @node, node, "dir" => "none", "color" => "green" )
@graph.add_edges( node, x.node, "dir" => "none", "color" => "green" )
@tree.add_couple( self, x, node )
end
def is_dead
@node["style"] = "filled"
end
def kids( *z )
GraphViz::FamilyTree::Couple.new( @graph, @node, [self] ).kids( *z )
end
end
end
end