Class: FamilySearch::Gedcomx::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/familysearch/gedcomx/graph.rb

Overview

The Graph takes a collection of objects and stitches persons together so that you can walk around the graph to different relationships.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraph

Returns a new instance of Graph.



13
14
15
16
17
# File 'lib/familysearch/gedcomx/graph.rb', line 13

def initialize()
  self.persons = []
  self.person_index = {}
  self.childAndParentsRelationships = []
end

Instance Attribute Details

#childAndParentsRelationshipsObject

Returns the value of attribute childAndParentsRelationships.



11
12
13
# File 'lib/familysearch/gedcomx/graph.rb', line 11

def childAndParentsRelationships
  @childAndParentsRelationships
end

#person_indexObject

Returns the value of attribute person_index.



10
11
12
# File 'lib/familysearch/gedcomx/graph.rb', line 10

def person_index
  @person_index
end

#personsObject

Returns the value of attribute persons.



9
10
11
# File 'lib/familysearch/gedcomx/graph.rb', line 9

def persons
  @persons
end

#rootObject

Returns the value of attribute root.



8
9
10
# File 'lib/familysearch/gedcomx/graph.rb', line 8

def root
  @root
end

Instance Method Details

#<<(familysearch) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/familysearch/gedcomx/graph.rb', line 19

def << (familysearch)
  person = familysearch.persons[0]
  # only add the person if it hasn't already been added
  if !self.person_index[person.id]
    graph_person = GraphPerson.new(person,self)
    self.persons << graph_person
    self.person_index[person.id] = graph_person
    self.root ||= graph_person
    # Update the childAndParentsRelationships
    update_cpr(familysearch)
  end
end

#person(id) ⇒ Object



32
33
34
# File 'lib/familysearch/gedcomx/graph.rb', line 32

def person(id)
  self.person_index[id]
end