Class: Gedcomx::Record

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = nil) ⇒ Record

Returns a new instance of Record.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gedcomx/record.rb', line 10

def initialize(input = nil)
  @record = input || self.class.java_class.new

  @people = []
  @people = @record.persons.map { |person| Gedcomx::Person.new(person) } if @record.persons

  @relationships = []
  if @record.relationships
    @relationships = @record.relationships.map { |relationship| Gedcomx::Relationship.new(relationship) }
  end
end

Instance Attribute Details

#peopleObject (readonly)

Returns the value of attribute people.



4
5
6
# File 'lib/gedcomx/record.rb', line 4

def people
  @people
end

#relationshipsObject (readonly)

Returns the value of attribute relationships.



4
5
6
# File 'lib/gedcomx/record.rb', line 4

def relationships
  @relationships
end

Class Method Details

.java_classObject



6
7
8
# File 'lib/gedcomx/record.rb', line 6

def self.java_class
  Java::OrgGedcomx::Gedcomx
end

Instance Method Details

#add_couple(person1, person2) ⇒ Object



42
43
44
# File 'lib/gedcomx/record.rb', line 42

def add_couple(person1, person2)
  relate_people(person1, person2, Gedcomx::TYPES[:couple])
end

#add_parent_child(parent, child) ⇒ Object



46
47
48
# File 'lib/gedcomx/record.rb', line 46

def add_parent_child(parent, child)
  relate_people(parent, child, Gedcomx::TYPES[:parent_child])
end

#add_person(person) ⇒ Object



22
23
24
25
26
# File 'lib/gedcomx/record.rb', line 22

def add_person(person)
  return false unless person.is_a? Gedcomx::Person
  @record.add_person(person.to_java)
  @people << person
end

#add_relationship(relationship) ⇒ Object



28
29
30
31
32
# File 'lib/gedcomx/record.rb', line 28

def add_relationship(relationship)
  return false unless relationship.is_a? Gedcomx::Relationship
  @record.add_relationship(relationship.to_java)
  @relationships << relationship
end

#each_personObject



50
51
52
53
54
# File 'lib/gedcomx/record.rb', line 50

def each_person
  @people.each do |person|
    yield person
  end
end

#each_relationshipObject



56
57
58
59
60
# File 'lib/gedcomx/record.rb', line 56

def each_relationship
  @relationships.each do |relationship|
    yield relationship
  end
end

#relate_people(person1, person2, type) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/gedcomx/record.rb', line 34

def relate_people(person1, person2, type)
  return false unless ( person1.is_a?(Gedcomx::Person) && person2.is_a?(Gedcomx::Person) )
  reference1 = Gedcomx::ResourceReference.create(resource: person1.relative_id)
  reference2 = Gedcomx::ResourceReference.create(resource: person2.relative_id)
  relationship = Gedcomx::Relationship.create(person1: reference1, person2: reference2, type: type)
  add_relationship(relationship)
end

#to_javaObject



62
63
64
# File 'lib/gedcomx/record.rb', line 62

def to_java
  @record
end