Sha256: 2e9f09c689f5e9308b8141a1faa071489499c785fb0b8a98b68e9202a89e772a
Contents?: true
Size: 1.36 KB
Versions: 3
Compression:
Stored size: 1.36 KB
Contents
require "familysearch/gedcomx/graph_person" module FamilySearch module Gedcomx # The Graph takes a collection of objects and stitches persons together # so that you can walk around the graph to different relationships. class Graph attr_accessor :root attr_accessor :persons attr_accessor :person_index attr_accessor :childAndParentsRelationships def initialize() self.persons = [] self.person_index = {} self.childAndParentsRelationships = [] end 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 def person(id) self.person_index[id] end private def update_cpr(familysearch) current_cpr = self.childAndParentsRelationships fs_cpr = familysearch.childAndParentsRelationships new_cpr = (current_cpr + fs_cpr).uniq self.childAndParentsRelationships = new_cpr end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
familysearch-gedcomx-1.0.2 | lib/familysearch/gedcomx/graph.rb |
familysearch-gedcomx-1.0.1 | lib/familysearch/gedcomx/graph.rb |
familysearch-gedcomx-1.0.0 | lib/familysearch/gedcomx/graph.rb |