Class: GraphViz::FamilyTree::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/graphviz/family_tree/person.rb

Instance Method Summary collapse

Constructor Details

#initialize(graph, tree, generation, id) ⇒ Person

:nodoc:



7
8
9
10
11
12
13
14
15
# File 'lib/graphviz/family_tree/person.rb', line 7

def initialize( graph, tree, generation, id ) #:nodoc:
  @graph = graph
  @node = @graph.add_nodes( id )
  @node["shape"] = "box"
  @tree = tree
  @generation = generation
  @x, @y = 0, 0
  @sibling = nil
end

Instance Method Details

#couplesObject

:nodoc:



33
34
35
# File 'lib/graphviz/family_tree/person.rb', line 33

def couples #:nodoc:
  @couples
end

#idObject



17
18
19
# File 'lib/graphviz/family_tree/person.rb', line 17

def id
  @node.id
end

#is_a_boy(name) ⇒ Object

Define the current person as a boy

greg.is_a_boy( "Greg" )


52
53
54
# File 'lib/graphviz/family_tree/person.rb', line 52

def is_a_boy( name )
  is_a_man( name )
end

#is_a_girl(name) ⇒ Object

Define the current perdon as a girl

maia.is_a_girl( "Maia" )


66
67
68
# File 'lib/graphviz/family_tree/person.rb', line 66

def is_a_girl( name )
  is_a_woman( name )
end

#is_a_man(name) ⇒ Object

Define the current person as a man

greg.is_a_man( "Greg" )


44
45
46
47
# File 'lib/graphviz/family_tree/person.rb', line 44

def is_a_man( name )
  @node["label"] = name
  @node["color"] = "blue"
end

#is_a_woman(name) ⇒ Object

Define the current perdon as a woman

mu.is_a_woman( "Muriel" )


59
60
61
62
# File 'lib/graphviz/family_tree/person.rb', line 59

def is_a_woman( name )
  @node["label"] = name
  @node["color"] = "pink"
end

#is_deadObject

Define the current person as dead

jack.is_dead


108
109
110
# File 'lib/graphviz/family_tree/person.rb', line 108

def is_dead
  @node["style"] = "filled"
end

#is_divorced_with(x) ⇒ Object

Define that’s two persons are divorced

sophie.is_divorced_with john


84
85
86
87
88
89
90
91
# File 'lib/graphviz/family_tree/person.rb', line 84

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

#is_maried_with(x) ⇒ Object

Define that’s two persons are maried

mu.is_maried_with greg


73
74
75
76
77
78
79
# File 'lib/graphviz/family_tree/person.rb', line 73

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

#is_widower_of(x) ⇒ Object

Define that’s a person is widower of another

simon.is_widower_of elisa


96
97
98
99
100
101
102
103
# File 'lib/graphviz/family_tree/person.rb', line 96

def is_widower_of( x ) #veuf
  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

#kids(*z) ⇒ Object

Define the kids of a single person

alice.kids( john, jack, julie )


115
116
117
# File 'lib/graphviz/family_tree/person.rb', line 115

def kids( *z )
  GraphViz::FamilyTree::Couple.new( @graph, @node, [self] ).kids( *z )
end

#nameObject



21
22
23
# File 'lib/graphviz/family_tree/person.rb', line 21

def name
  @node.label || @node.id
end

#nodeObject

:nodoc:



37
38
39
# File 'lib/graphviz/family_tree/person.rb', line 37

def node #:nodoc:
  @node
end

#siblingObject



25
26
27
# File 'lib/graphviz/family_tree/person.rb', line 25

def sibling
  @sibling
end

#sibling=(x) ⇒ Object



29
30
31
# File 'lib/graphviz/family_tree/person.rb', line 29

def sibling=(x)
  @sibling=x
end