class FamilySearch::Gedcomx::Graph
The Graph
takes a collection of objects and stitches persons together so that you can walk around the graph to different relationships.
Attributes
childAndParentsRelationships[RW]
person_index[RW]
persons[RW]
root[RW]
Public Class Methods
new()
click to toggle source
# File lib/familysearch/gedcomx/graph.rb, line 13 def initialize() self.persons = [] self.person_index = {} self.childAndParentsRelationships = [] end
Public Instance Methods
<<(familysearch)
click to toggle source
# 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)
click to toggle source
# File lib/familysearch/gedcomx/graph.rb, line 32 def person(id) self.person_index[id] end
Private Instance Methods
update_cpr(familysearch)
click to toggle source
# File lib/familysearch/gedcomx/graph.rb, line 37 def update_cpr(familysearch) current_cpr = self.childAndParentsRelationships fs_cpr = familysearch.childAndParentsRelationships new_cpr = (current_cpr + fs_cpr).uniq self.childAndParentsRelationships = new_cpr end