Class: GraphViz::FamilyTree

Inherits:
Object show all
Defined in:
lib/graphviz/family_tree.rb,
lib/graphviz/family_tree/couple.rb,
lib/graphviz/family_tree/person.rb,
lib/graphviz/family_tree/sibling.rb,
lib/graphviz/family_tree/generation.rb

Defined Under Namespace

Classes: Couple, Generation, Person, Sibling

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ FamilyTree

Create a new family tree

require 'graphviz/family_tree'
t = GraphViz::FamilyTree.new do
  ...
end


18
19
20
21
22
23
24
25
26
# File 'lib/graphviz/family_tree.rb', line 18

def initialize( &block )
  @persons = {}
  @graph = GraphViz.new( "FamilyTree", :use => :neato )
  @generation_number = 0
  @generations = []
  @couples = {}

  instance_eval(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

:nodoc:



62
63
64
# File 'lib/graphviz/family_tree.rb', line 62

def method_missing(sym, *args, &block) #:nodoc:
  persons[sym.to_s]
end

Instance Method Details

#add_couple(x, y, node) ⇒ Object

:nodoc:



50
51
52
53
54
55
# File 'lib/graphviz/family_tree.rb', line 50

def add_couple( x, y, node ) #:nodoc:
  @couples[x] = {} if @couples[x].nil?
  @couples[x][y] = GraphViz::FamilyTree::Couple.new( @graph, node, [x, y] )
  @couples[y] = {} if @couples[y].nil?
  @couples[y][x] = @couples[x][y]
end

#couple(x, y) ⇒ Object

Get a couple (GraphViz::FamilyTree::Couple)



58
59
60
# File 'lib/graphviz/family_tree.rb', line 58

def couple( x, y )
  @couples[x][y]
end

#generation(&b) ⇒ Object

Add a new generation in the tree

require 'graphviz/family_tree'
t = GraphViz::FamilyTree.new do
  generation do
    ...
  end
  generation do
    ...
  end
end


39
40
41
42
43
44
# File 'lib/graphviz/family_tree.rb', line 39

def generation( &b )
  gen = GraphViz::FamilyTree::Generation.new( @graph, @persons, self, @generation_number )
  gen.make( &b )
  @generations << gen
  @generation_number += 1
end

#graphObject

Get the graph



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/graphviz/family_tree.rb', line 72

def graph
  maxY = @generations.size
  biggestGen, maxX = biggestGenerationNumberAndSize

  puts "#{maxY} generations"
  puts "Plus grosse generation : ##{biggestGen} avec #{maxX} personnes"

  puts "traitement des générations..."

  puts "  #{biggestGen}:"
  @generations[biggestGen].persons.each do |id, person|
    puts "    - #{id} : #{person.class}"
  end

  puts "  Up..."
  (0...biggestGen).reverse_each do |genNumber|
    puts "  #{genNumber}:"
    @generations[genNumber].persons.each do |id, person|
      puts "    - #{id} : #{person.class}"
    end
  end

  puts "  Down..."
  ((biggestGen+1)...maxY).each do |genNumber|
    puts "  #{genNumber}:"
    @generations[genNumber].persons.each do |id, person|
      puts "    - #{id} : #{person.class}"
    end
  end

  @graph
end

#personsObject

:nodoc:



46
47
48
# File 'lib/graphviz/family_tree.rb', line 46

def persons #:nodoc:
  @persons ||= {}
end

#sizeObject

Family size



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

def size
  @persons.size
end