Class: Gedcomx::Person

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = nil) ⇒ Person

Returns a new instance of Person.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gedcomx/person.rb', line 21

def initialize(input = nil)
  @person = input || self.class.java_class.new
  @gender = Gedcomx::Gender.new(@person.get_gender) if @person.get_gender
  @identifiers = []
  @identifiers = @person.identifiers.map { |identifier| Gedcomx::Identifier.new(identifier) } if @person.identifiers
  @names = []
  @names = @person.names.map { |name| Gedcomx::Name.new(name) } if @person.names
  @facts = []
  @facts = @person.facts.map { |fact| Gedcomx::Fact.new(fact) } if @person.facts
  @fields = []
  @fields = @person.fields.map { |field| Gedcomx::Field.new(field) } if @person.fields
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(something) ⇒ Object (protected)



209
210
211
# File 'lib/gedcomx/person.rb', line 209

def method_missing(something)
  @person.send(something)
end

Instance Attribute Details

#factsObject (readonly)

Returns the value of attribute facts.



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

def facts
  @facts
end

#fieldsObject (readonly)

Returns the value of attribute fields.



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

def fields
  @fields
end

#genderObject (readonly)

Returns the value of attribute gender.



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

def gender
  @gender
end

#identifiersObject (readonly)

Returns the value of attribute identifiers.



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

def identifiers
  @identifiers
end

#namesObject (readonly)

Returns the value of attribute names.



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

def names
  @names
end

Class Method Details

.create(attributes = {}) ⇒ Object



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

def self.create(attributes = {})
  new_person = self.new
  new_person.principal = attributes[:principal] if attributes[:principal]
  new_person.relative_id = attributes[:relative_id] if attributes[:relative_id]
  attributes[:fields].each { |field| new_person.add_field(field) } if attributes[:fields].is_a? Array
  attributes[:facts].each { |fact| new_person.add_fact(fact) } if attributes[:facts].is_a? Array
  attributes[:names].each { |name| new_person.add_name(name) } if attributes[:names].is_a? Array
  attributes[:identifiers].each { |id| new_person.add_identifier(id) } if attributes[:identifiers].is_a? Array
  new_person
end

.java_classObject



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

def self.java_class
  Java::OrgGedcomxConclusion::Person
end

Instance Method Details

#add_birthday(info = {}) ⇒ Object



108
109
110
111
112
# File 'lib/gedcomx/person.rb', line 108

def add_birthday(info = {})
  birth_date = Gedcomx::Date.create_simple(info)
  birth_fact = Gedcomx::Fact.create(date: birth_date, type: Gedcomx::TYPES[:birth])
  add_fact(birth_fact)
end

#add_fact(fact) ⇒ Object



84
85
86
87
88
# File 'lib/gedcomx/person.rb', line 84

def add_fact(fact)
  return false unless fact.is_a? Gedcomx::Fact
  @person.add_fact(fact.to_java)
  @facts << fact
end

#add_field(field) ⇒ Object



90
91
92
93
94
# File 'lib/gedcomx/person.rb', line 90

def add_field(field)
  return false unless field.is_a? Gedcomx::Field
  @person.add_field(field.to_java)
  @fields << field
end

#add_identifier(identifier) ⇒ Object



96
97
98
99
100
# File 'lib/gedcomx/person.rb', line 96

def add_identifier(identifier)
  return false unless identifier.is_a? Gedcomx::Identifier
  @person.add_identifier identifier.to_java
  @identifiers << identifier
end

#add_name(name) ⇒ Object



102
103
104
105
106
# File 'lib/gedcomx/person.rb', line 102

def add_name(name)
  return false unless name.is_a? Gedcomx::Name
  @person.add_name name.to_java
  @names << name
end

#birth_dateObject



131
132
133
134
135
136
137
# File 'lib/gedcomx/person.rb', line 131

def birth_date
  birthday_obj = Gedcomx.get_first_fact(@person, :birth)
  unless birthday_obj.nil?
    birth_date_obj = birthday_obj.get_date
    get_date(birth_date_obj)
  end
end

#event_dateObject



123
124
125
126
127
128
129
# File 'lib/gedcomx/person.rb', line 123

def event_date
  primary_fact = self.primary_fact
  unless primary_fact.nil?
    primary_date = primary_fact.get_date
    return get_date(primary_date) unless primary_date.nil?
  end
end

#female?Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/gedcomx/person.rb', line 39

def female?
  gender = @person.get_gender.get_type.to_s
  gender == TYPES[:female]
end

#first_value(type) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/gedcomx/person.rb', line 139

def first_value(type)
  field = Gedcomx.get_first_field(@person, type)
  unless field.nil?
    interpreted = Gedcomx.interpreted_value(field)
    return interpreted.get_text unless interpreted.nil?
    return nil
  end
  fact = Gedcomx.get_first_fact(@person, type)
  unless fact.nil?
    fact.get_value
  end
end

#gender_typeObject



44
45
46
47
# File 'lib/gedcomx/person.rb', line 44

def gender_type
  return TYPES[:male] if male?
  TYPES[:female] if female?
end

#locationObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/gedcomx/person.rb', line 152

def location
  primary_fact = @person.facts.find{|fact| fact.get_primary }

  location = primary_fact.get_place
  location_params = {}
  location_params[:name] = location.get_original

  # Fill in the location level definitions
  location_levels = {}
  location_fields = @person.fields.select{|field| field.get_type.to_s.include? 'EVENT_PLACE_LEVEL_' }
  location_fields.each do |field|
    value = field.get_values[0].get_text
    level = /EVENT_PLACE_LEVEL_\d/.match(field.get_type.to_s)[0]
    location_levels[level] = value
  end

  # Match the location name to the appropriate level
  location.get_fields.each do |field|
    value = Gedcomx.interpreted_value(field)

    # Store the level if it is valid
    level = location_levels[value.label_id]
    next if level.nil?
    mapped_value = Gedcomx.location_mapping(level)
    next if mapped_value.nil?
    location_params[mapped_value] = value.get_text
  end

  location_params
end

#male?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/gedcomx/person.rb', line 34

def male?
  gender = @person.get_gender.get_type.to_s
  gender == TYPES[:male]
end

#names_hashObject

Returns a list of name hashes



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gedcomx/person.rb', line 64

def names_hash
  names_list = []
  @person.names.each do |name_obj|
    name_obj.name_forms.each do |name_form_obj|
      name_hash = {}
      name_hash[:full] = name_form_obj.get_full_text
      first_name = name_form_obj.parts.find{|part| part.get_type.to_s == TYPES[:given] }
      unless first_name.nil?
        name_hash[:first] = first_name.get_value
      end
      last_name = name_form_obj.parts.find{|part| part.get_type.to_s == TYPES[:surname] }
      unless last_name.nil?
        name_hash[:last] = last_name.get_value
      end
      names_list << name_hash
    end
  end
  names_list
end

#principal=(input_boolean) ⇒ Object



118
119
120
121
# File 'lib/gedcomx/person.rb', line 118

def principal=(input_boolean)
  return false unless input_boolean.is_a? Boolean
  @person.principal = input_boolean
end

#principal?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/gedcomx/person.rb', line 114

def principal?
  @person.get_principal
end

#relative_idObject



183
184
185
# File 'lib/gedcomx/person.rb', line 183

def relative_id
  @person.get_id
end

#relative_id=(id_string) ⇒ Object



187
188
189
190
# File 'lib/gedcomx/person.rb', line 187

def relative_id=(id_string)
  return false unless id_string.is_a? String
  @person.id = id_string
end

#set_gender(gender) ⇒ Object



49
50
51
52
53
# File 'lib/gedcomx/person.rb', line 49

def set_gender(gender)
  return false unless gender.is_a? Gedcomx::Gender
  @person.gender = gender.to_java
  @gender = gender
end

#set_gender_femaleObject



59
60
61
# File 'lib/gedcomx/person.rb', line 59

def set_gender_female
  set_gender(Gedcomx::Gender.create_female)
end

#set_gender_maleObject



55
56
57
# File 'lib/gedcomx/person.rb', line 55

def set_gender_male
  set_gender(Gedcomx::Gender.create_male)
end

#to_javaObject



192
193
194
# File 'lib/gedcomx/person.rb', line 192

def to_java
  @person
end