ruby-fs-stack 0.4.12 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/README.rdoc +25 -1
  2. data/VERSION +1 -1
  3. data/lib/ruby-fs-stack/familytree.rb +13 -1435
  4. data/lib/ruby-fs-stack/familytree/characteristic.rb +12 -0
  5. data/lib/ruby-fs-stack/familytree/communicator.rb +412 -0
  6. data/lib/ruby-fs-stack/familytree/event.rb +49 -0
  7. data/lib/ruby-fs-stack/familytree/exist.rb +8 -0
  8. data/lib/ruby-fs-stack/familytree/gender.rb +9 -0
  9. data/lib/ruby-fs-stack/familytree/match.rb +3 -0
  10. data/lib/ruby-fs-stack/familytree/name.rb +69 -0
  11. data/lib/ruby-fs-stack/familytree/note.rb +48 -0
  12. data/lib/ruby-fs-stack/familytree/ordinance.rb +70 -0
  13. data/lib/ruby-fs-stack/familytree/pedigree.rb +103 -0
  14. data/lib/ruby-fs-stack/familytree/person.rb +495 -0
  15. data/lib/ruby-fs-stack/familytree/relationship.rb +209 -0
  16. data/lib/ruby-fs-stack/familytree/search.rb +27 -0
  17. data/lib/ruby-fs-stack/identity.rb +1 -37
  18. data/lib/ruby-fs-stack/identity/communicator.rb +41 -0
  19. data/ruby-fs-stack.gemspec +59 -43
  20. data/spec/{familytree_v2/familytree_communicator_spec.rb → ruby-fs-stack/familytree/communicator_spec.rb} +91 -1
  21. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/combine_request.js +0 -0
  22. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/combine_response.js +0 -0
  23. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/fakeweb_contributor.txt +0 -0
  24. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/fakeweb_pedigree.txt +0 -0
  25. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/fakeweb_pedigree2.txt +0 -0
  26. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/fakeweb_properties.txt +0 -0
  27. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/match_KW3B-NNM.js +0 -0
  28. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/note_create_response.js +0 -0
  29. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/KJ86-3VD_all.js +0 -0
  30. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/KJ86-3VD_parents_families.js +0 -0
  31. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/KJ86-3VD_version.js +0 -0
  32. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/fakeweb_10_batch.txt +0 -0
  33. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/fakeweb_6_batch.txt +0 -0
  34. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/multiple_version_read.js +0 -0
  35. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/post_response.js +0 -0
  36. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/relationship_not_found.js +0 -0
  37. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/relationship_read.js +0 -0
  38. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/relationship_update.js +0 -0
  39. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/person/spouse_read.js +0 -0
  40. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/json/search.js +0 -0
  41. data/spec/{familytree_v2/match_results_spec.rb → ruby-fs-stack/familytree/match_spec.rb} +1 -1
  42. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/note_spec.rb +1 -1
  43. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/pedigree_spec.rb +1 -1
  44. data/spec/{familytree_v2 → ruby-fs-stack/familytree}/person_spec.rb +1 -3
  45. data/spec/{familytree_v2/relationships_spec.rb → ruby-fs-stack/familytree/relationship_spec.rb} +1 -3
  46. data/spec/{familytree_v2/search_results_spec.rb → ruby-fs-stack/familytree/search_spec.rb} +1 -1
  47. data/spec/ruby-fs-stack/familytree/spec_helper.rb +2 -0
  48. data/spec/{communicator_spec.rb → ruby-fs-stack/fs_communicator_spec.rb} +5 -5
  49. data/spec/{fs_utils_spec.rb → ruby-fs-stack/fs_utils_spec.rb} +1 -1
  50. data/spec/ruby-fs-stack/identity/communicator_spec.rb +82 -0
  51. data/spec/{identity_v1 → ruby-fs-stack/identity}/json/login.js +0 -0
  52. metadata +61 -45
  53. data/spec/identity_v1/identity_spec.rb +0 -50
@@ -0,0 +1,8 @@
1
+ module Org::Familysearch::Ws::Familytree::V2::Schema
2
+
3
+ class ExistsAssertion
4
+ def add_value
5
+ self.value = ExistsValue.new
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module Org::Familysearch::Ws::Familytree::V2::Schema
2
+
3
+ class GenderAssertion
4
+ def add_value(value)
5
+ self.value = GenderValue.new
6
+ self.value.type = value
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ # Not extending any match stuff yet.
2
+ # All modifications to Match have been done through Search
3
+ # because Match inherits from Search.
@@ -0,0 +1,69 @@
1
+ module Org::Familysearch::Ws::Familytree::V2::Schema
2
+
3
+ class NameForm
4
+ def set_name(name)
5
+ split_pieces = name.match(/(.*)\/(.*)\//)
6
+ # if there is a name like John Jacob /Felch/, split to name pieces, otherwise use fullText
7
+ if split_pieces
8
+ given_pieces = split_pieces[1]
9
+ family_pieces = split_pieces[2]
10
+ self.pieces = given_pieces.split(" ").collect do |piece|
11
+ p = NamePiece.new
12
+ p.type = "Given"
13
+ p.postdelimiters = " "
14
+ p.value = piece
15
+ p
16
+ end
17
+ self.pieces = self.pieces + family_pieces.split(" ").collect do |piece|
18
+ p = NamePiece.new
19
+ p.type = "Family"
20
+ p.predelimiters = ""
21
+ p.value = piece
22
+ p
23
+ end
24
+ else
25
+ self.fullText = name
26
+ end
27
+ end
28
+
29
+ def surname
30
+ if self.pieces.nil?
31
+ (self.fullText.nil?) ? nil : self.fullText.split(' ').last
32
+ else
33
+ piece = self.pieces.find{|piece|piece.type == 'Family'}
34
+ (piece.nil?) ? nil : piece.value
35
+ end
36
+ end
37
+
38
+ def buildFullText
39
+ if self.pieces.nil?
40
+ return ''
41
+ else
42
+ self.pieces.collect{|piece| "#{piece.predelimiters}#{piece.value}#{piece.postdelimiters}"}.join('')
43
+ end
44
+ end
45
+ end
46
+
47
+ class NameValue
48
+ def add_form(value)
49
+ self.forms = []
50
+ f = NameForm.new
51
+ f.set_name(value)
52
+ self.forms << f
53
+ end
54
+
55
+ end
56
+
57
+ class NameAssertion
58
+ def add_value(value)
59
+ self.value = NameValue.new
60
+ self.value.add_form(value)
61
+ end
62
+
63
+ def select(value_id)
64
+ self.action = 'Select'
65
+ self.value = AssertionValue.new
66
+ self.value.id = value_id
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,48 @@
1
+ module Org::Familysearch::Ws::Familytree::V2::Schema
2
+ class Note
3
+
4
+ #Builds out the elements needed for the note.
5
+ # ====Params
6
+ # * <tt>options</tt> - Options for the note including the following:
7
+ # * <tt>:personId</tt> - the person ID if attaching to a person assertion.
8
+ # * <tt>:spouseIds</tt> - an Array of spouse IDs if creating a note attached to a spouse
9
+ # relationship assertion.
10
+ # * <tt>:parentIds</tt> - an Array of parent IDs if creating a note attached to a parent
11
+ # relationship assertion. If creating a note for a child-parent or parent-child
12
+ # relationship, you will need only one parent ID in the array along with a :childId option.
13
+ # * <tt>:childId</tt> - a child ID.
14
+ # * <tt>:text</tt> - the text of the note (required).
15
+ # * <tt>:assertionId</tt> - the valueId of the assertion you are attaching this note to.
16
+ def build(options)
17
+ if spouseIds = options[:spouseIds]
18
+ self.spouses = spouseIds.collect do |id|
19
+ s = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
20
+ s.id = id
21
+ s
22
+ end
23
+ end
24
+ if parentIds = options[:parentIds]
25
+ self.parents = parentIds.collect do |id|
26
+ p = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
27
+ p.id = id
28
+ p
29
+ end
30
+ end
31
+ if personId = options[:personId]
32
+ self.person = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
33
+ self.person.id = personId
34
+ end
35
+ if childId = options[:childId]
36
+ self.child = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
37
+ self.child.id = childId
38
+ end
39
+ if assertionId = options[:assertionId]
40
+ self.assertion = Org::Familysearch::Ws::Familytree::V2::Schema::EntityReference.new
41
+ self.assertion.id = assertionId
42
+ end
43
+ if text = options[:text]
44
+ self.text = text
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,70 @@
1
+ module Org::Familysearch::Ws::Familytree::V2::Schema
2
+
3
+ class OrdinanceType
4
+
5
+ # Born in Covenant -> Possibly needs to be changed to no underscores
6
+ # Born_in_Covenant = "Born_in_Covenant"
7
+
8
+ # Override the incorrect constants in the enunciate library
9
+ with_warnings_suppressed do
10
+ # Sealing to parents.
11
+ Sealing_to_Parents = "Sealing to Parents"
12
+
13
+ # Sealing to spouse.
14
+ Sealing_to_Spouse = "Sealing to Spouse"
15
+ end
16
+ end
17
+
18
+
19
+ class OrdinanceValue
20
+
21
+ def add_date(value)
22
+ self.date = GenDate.new
23
+ self.date.original = value
24
+ end
25
+
26
+ def add_place(value)
27
+ self.place = Place.new
28
+ self.place.original = value
29
+ end
30
+
31
+ def add_mother(mother_id)
32
+ add_parent('Female',mother_id)
33
+ end
34
+
35
+ def add_father(father_id)
36
+ add_parent('Male',father_id)
37
+ end
38
+
39
+ def add_parent(gender, id)
40
+ add_parents!
41
+ parent = PersonReference.new
42
+ parent.id = id
43
+ parent.gender = gender
44
+ self.parents << parent
45
+ end
46
+
47
+ private
48
+ def add_parents!
49
+ self.parents ||= []
50
+ end
51
+
52
+ end
53
+
54
+ class OrdinanceAssertion
55
+
56
+ def add_value(options)
57
+ raise ArgumentError, "missing option[:type]" if options[:type].nil?
58
+ raise ArgumentError, "missing option[:place]" if options[:place].nil?
59
+ self.value = OrdinanceValue.new
60
+ self.value.type = options[:type]
61
+ self.value.add_date(options[:date]) if options[:date]
62
+ self.value.add_place(options[:place]) if options[:place]
63
+ self.value.temple = options[:temple] if options[:temple]
64
+ if options[:type] == OrdinanceType::Sealing_to_Parents
65
+ self.value.add_mother(options[:mother])
66
+ self.value.add_father(options[:father])
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,103 @@
1
+ module Org::Familysearch::Ws::Familytree::V2::Schema
2
+ class PedigreePerson < Person
3
+ attr_accessor :pedigree
4
+
5
+ def initialize(pedigree = nil, person = nil)
6
+ if person
7
+ @id = person.id
8
+ # @version = person.version if person.version
9
+ @assertions = person.assertions if person.assertions
10
+ @families = person.families if person.families
11
+ @parents = person.parents if person.parents
12
+ @properties = person.properties if person.properties
13
+ end
14
+ if pedigree
15
+ @pedigree = pedigree
16
+ end
17
+ end
18
+
19
+ def father
20
+ pedigree.get_person(father_id)
21
+ end
22
+
23
+ def mother
24
+ pedigree.get_person(mother_id)
25
+ end
26
+
27
+ end
28
+
29
+
30
+
31
+ class Pedigree
32
+ attr_accessor :person_hash
33
+
34
+ def initialize
35
+ @person_hash = {}
36
+ @persons = []
37
+ end
38
+
39
+ def injest(pedigree)
40
+ @person_hash.merge!(pedigree.person_hash)
41
+ graft_persons_to_self(pedigree.persons)
42
+ @persons = @persons + pedigree.persons
43
+ end
44
+
45
+ def <<(person)
46
+ p = PedigreePerson.new(self, person)
47
+ @persons << p
48
+ @person_hash[p.id] = p
49
+ end
50
+
51
+ def continue_nodes
52
+ @persons.select do |person|
53
+ (!person.mother_id.nil? && person.mother.nil?) || (!person.father_id.nil? && person.father.nil?)
54
+ end
55
+ end
56
+
57
+ def continue_node_ids
58
+ continue_nodes.collect{|n|n.id}
59
+ end
60
+
61
+ def continue_ids
62
+ cns = continue_nodes
63
+ father_ids = cns.select{|n|!n.father_id.nil?}.collect{|n|n.father_id}
64
+ mother_ids = cns.select{|n|!n.mother_id.nil?}.collect{|n|n.mother_id}
65
+ father_ids + mother_ids
66
+ end
67
+
68
+ def get_person(id)
69
+ @person_hash[id]
70
+ end
71
+
72
+ def person_ids
73
+ @persons.collect{|p|p.id}
74
+ end
75
+
76
+ def init_jaxb_json_hash(_o)
77
+ @id = String.from_json(_o['id']) unless _o['id'].nil?
78
+ @requestedId = String.from_json(_o['requestedId']) unless _o['requestedId'].nil?
79
+ if !_o['persons'].nil?
80
+ @persons = Array.new
81
+ _oa = _o['persons']
82
+ _oa.each do | _item |
83
+ pedigree_person = Org::Familysearch::Ws::Familytree::V2::Schema::PedigreePerson.from_json(_item)
84
+ pedigree_person.pedigree = self
85
+ @persons.push pedigree_person
86
+ @person_hash[pedigree_person.id] = pedigree_person
87
+ end
88
+ end
89
+ end
90
+
91
+ def root
92
+ persons.first
93
+ end
94
+
95
+ private
96
+ def graft_persons_to_self(persons_to_graft)
97
+ persons_to_graft.each do |person|
98
+ person.pedigree = self
99
+ end
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,495 @@
1
+ module Org::Familysearch::Ws::Familytree::V2::Schema
2
+
3
+ class PersonAssertions
4
+ def add_gender(value)
5
+ self.genders ||= []
6
+ g = GenderAssertion.new
7
+ g.add_value(value)
8
+ self.genders << g
9
+ end
10
+
11
+ def add_name(value)
12
+ self.names ||= []
13
+ n = NameAssertion.new
14
+ n.add_value(value)
15
+ self.names << n
16
+ end
17
+
18
+ def select_name(value_id)
19
+ self.names ||= []
20
+ n = NameAssertion.new
21
+ n.select(value_id)
22
+ self.names << n
23
+ end
24
+
25
+ def add_event(options)
26
+ self.events ||= []
27
+ e = EventAssertion.new
28
+ e.add_value(options)
29
+ self.events << e
30
+ end
31
+
32
+ def select_event_summary(type,value_id)
33
+ self.events ||= []
34
+ e = EventAssertion.new
35
+ e.select(type,value_id)
36
+ self.events << e
37
+ end
38
+
39
+ def add_ordinance(options)
40
+ self.ordinances ||= []
41
+ o = OrdinanceAssertion.new
42
+ o.add_value(options)
43
+ self.ordinances << o
44
+ end
45
+
46
+ end
47
+
48
+ class Person
49
+
50
+ def full_names
51
+ if assertions && assertions.names
52
+ return assertions.names.collect do |name|
53
+ (name.value.forms[0].fullText.nil?) ? name.value.forms[0].buildFullText : name.value.forms[0].fullText
54
+ end
55
+ else
56
+ []
57
+ end
58
+ end
59
+
60
+ def full_name
61
+ self.full_names.first
62
+ end
63
+
64
+ def surnames
65
+ if assertions && assertions.names
66
+ names = assertions.names.collect do |name|
67
+ name.value.forms[0].surname
68
+ end
69
+ return names.reject{|n|n.nil?}
70
+ else
71
+ []
72
+ end
73
+ end
74
+
75
+ def surname
76
+ surnames.first
77
+ end
78
+
79
+ def gender
80
+ if assertions && assertions.genders && assertions.genders[0] && assertions.genders[0].value
81
+ assertions.genders[0].value.type
82
+ else
83
+ nil
84
+ end
85
+ end
86
+
87
+ # Convenience method for adding the gender.
88
+ #
89
+ # ====Params
90
+ # <tt>value</tt> - 'Male' or 'Female'
91
+ def add_gender(value)
92
+ add_assertions!
93
+ assertions.add_gender(value)
94
+ end
95
+
96
+ # Convenience method for adding a name. It fills in the necessary
97
+ # structure underneath to create the name.
98
+ #
99
+ # ====Params
100
+ # <tt>value</tt> - the name to be added
101
+ #
102
+ # ====Example
103
+ #
104
+ # person.add_name 'Parker Felch' # Sets the fullText to "Parker Felch"
105
+ # person.add_name 'Parker Jones /Felch/' # Does not set the fullText, but sets the name pieces.
106
+ def add_name(value)
107
+ add_assertions!
108
+ assertions.add_name(value)
109
+ end
110
+
111
+ # Select the name for the summary view. This should be called on a Person record that
112
+ # contains a person id and version.
113
+ #
114
+ # ====Params
115
+ # <tt>value_id</tt> - the value id of a name assertion that you would like to set as the summary
116
+ #
117
+ # ===Example
118
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
119
+ # person.select_name_summary('1000134')
120
+ # com.familytree_v2.save_person person
121
+ #
122
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
123
+ def select_name_summary(value_id)
124
+ add_assertions!
125
+ assertions.select_name(value_id)
126
+ end
127
+
128
+ def births
129
+ select_events('Birth')
130
+ end
131
+
132
+ # It should return the selected birth assertion unless it is
133
+ # not set in which case it will return the first
134
+ def birth
135
+ birth = births.find{|b|!b.selected.nil?}
136
+ birth ||= births[0]
137
+ birth
138
+ end
139
+
140
+ def deaths
141
+ select_events('Death')
142
+ end
143
+
144
+ # It should return the selected death assertion unless it is
145
+ # not set in which case it will return the first
146
+ def death
147
+ death = deaths.find{|b|!b.selected.nil?}
148
+ death ||= deaths[0]
149
+ death
150
+ end
151
+
152
+ # This should only be called on a person containing relationships
153
+ def marriages(for_person)
154
+ select_spouse_events('Marriage',for_person)
155
+ end
156
+
157
+ # This should only be called on a person containing relationships
158
+ def divorces(for_person)
159
+ select_spouse_events('Divorce',for_person)
160
+ end
161
+
162
+ # Add an event with type of Birth
163
+ #
164
+ # ====Params
165
+ # * <tt>options</tt> - accepts a :date and :place option
166
+ #
167
+ # ====Example
168
+ #
169
+ # person.add_birth :date => '12 Aug 1902', :place => 'United States'
170
+ def add_birth(options)
171
+ add_assertions!
172
+ options[:type] = 'Birth'
173
+ assertions.add_event(options)
174
+ end
175
+
176
+ # Select the birth for the summary view. This should be called on a Person record that
177
+ # contains a person id and version.
178
+ #
179
+ # ====Params
180
+ # <tt>value_id</tt> - the value id of a birth assertion that you would like to set as the summary
181
+ #
182
+ # ===Example
183
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
184
+ # person.select_birth_summary('1000134')
185
+ # com.familytree_v2.save_person person
186
+ #
187
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
188
+ def select_birth_summary(value_id)
189
+ add_assertions!
190
+ assertions.select_event_summary('Birth',value_id)
191
+ end
192
+
193
+ # Add an event with type of Birth
194
+ #
195
+ # ====Params
196
+ # * <tt>options</tt> - accepts a :date and :place option
197
+ #
198
+ # ====Example
199
+ #
200
+ # person.add_birth :date => '12 Aug 1902', :place => 'United States'
201
+ def add_death(options)
202
+ add_assertions!
203
+ options[:type] = 'Death'
204
+ assertions.add_event(options)
205
+ end
206
+
207
+ # Select the death for the summary view. This should be called on a Person record that
208
+ # contains a person id and version.
209
+ #
210
+ # ====Params
211
+ # <tt>value_id</tt> - the value id of a death assertion that you would like to set as the summary
212
+ #
213
+ # ===Example
214
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
215
+ # person.select_death_summary('1000134')
216
+ # com.familytree_v2.save_person person
217
+ #
218
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
219
+ def select_death_summary(value_id)
220
+ add_assertions!
221
+ assertions.select_event_summary('Death',value_id)
222
+ end
223
+
224
+ # Select the mother for the summary view. This should be called on a Person record that
225
+ # contains a person id and version.
226
+ #
227
+ # Make sure you set both the mother and father before saving the person. Otherwise you will
228
+ # set a single parent as the summary.
229
+ #
230
+ # ====Params
231
+ # <tt>person_id</tt> - the person id of the mother that you would like to set as the summary
232
+ #
233
+ # ===Example
234
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
235
+ # person.select_mother_summary('KWQS-BBQ')
236
+ # person.select_father_summary('KWQS-BBT')
237
+ # com.familytree_v2.save_person person
238
+ #
239
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
240
+ def select_mother_summary(person_id)
241
+ add_parents!
242
+ couple = parents[0] || ParentsReference.new
243
+ couple.select_parent(person_id,'Female')
244
+ parents[0] = couple
245
+ end
246
+
247
+ # Select the father for the summary view. This should be called on a Person record that
248
+ # contains a person id and version.
249
+ #
250
+ # Make sure you set both the mother and father before saving the person. Otherwise you will
251
+ # set a single parent as the summary.
252
+ #
253
+ # ====Params
254
+ # <tt>person_id</tt> - the person id of the father that you would like to set as the summary
255
+ #
256
+ # ===Example
257
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
258
+ # person.select_father_summary('KWQS-BBQ')
259
+ # person.select_mother_summary('KWQS-BBT')
260
+ # com.familytree_v2.save_person person
261
+ #
262
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
263
+ def select_father_summary(person_id)
264
+ add_parents!
265
+ couple = parents[0] || ParentsReference.new
266
+ couple.select_parent(person_id,'Male')
267
+ parents[0] = couple
268
+ end
269
+
270
+ # Select the spouse for the summary view. This should be called on a Person record that
271
+ # contains a person id and version.
272
+ #
273
+ # ====Params
274
+ # <tt>person_id</tt> - the person id of the spouse that you would like to set as the summary
275
+ #
276
+ # ===Example
277
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
278
+ # person.select_spouse_summary('KWQS-BBQ')
279
+ # com.familytree_v2.save_person person
280
+ #
281
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
282
+ def select_spouse_summary(person_id)
283
+ add_families!
284
+ family = FamilyReference.new
285
+ family.select_spouse(person_id)
286
+ families << family
287
+ end
288
+
289
+ def baptisms
290
+ select_ordinances('Baptism')
291
+ end
292
+
293
+ def confirmations
294
+ select_ordinances('Confirmation')
295
+ end
296
+
297
+ def initiatories
298
+ select_ordinances('Initiatory')
299
+ end
300
+
301
+ def endowments
302
+ select_ordinances('Endowment')
303
+ end
304
+
305
+ def sealing_to_parents
306
+ select_ordinances(OrdinanceType::Sealing_to_Parents)
307
+ end
308
+
309
+ def sealing_to_spouses(id)
310
+ select_relationship_ordinances(:relationship_type => 'spouse', :id => id, :type => OrdinanceType::Sealing_to_Spouse)
311
+ end
312
+
313
+ # Add a baptism ordinance
314
+ #
315
+ # ====Params
316
+ # * <tt>options</tt> - accepts a :date, :place, and :temple option
317
+ #
318
+ # ====Example
319
+ #
320
+ # person.add_baptism :date => '14 Aug 2009', :temple => 'SGEOR', :place => 'Salt Lake City, Utah'
321
+ def add_baptism(options)
322
+ add_assertions!
323
+ options[:type] = 'Baptism'
324
+ assertions.add_ordinance(options)
325
+ end
326
+
327
+ # Add a confirmation ordinance
328
+ #
329
+ # ====Params
330
+ # * <tt>options</tt> - accepts a :date, :place, and :temple option
331
+ #
332
+ # ====Example
333
+ #
334
+ # person.add_confirmation :date => '14 Aug 2009', :temple => 'SGEOR', :place => 'Salt Lake City, Utah'
335
+ def add_confirmation(options)
336
+ add_assertions!
337
+ options[:type] = 'Confirmation'
338
+ assertions.add_ordinance(options)
339
+ end
340
+
341
+ # Add a initiatory ordinance
342
+ #
343
+ # ====Params
344
+ # * <tt>options</tt> - accepts a :date, :place, and :temple option
345
+ #
346
+ # ====Example
347
+ #
348
+ # person.add_initiatory :date => '14 Aug 2009', :temple => 'SGEOR', :place => 'Salt Lake City, Utah'
349
+ def add_initiatory(options)
350
+ add_assertions!
351
+ options[:type] = 'Initiatory'
352
+ assertions.add_ordinance(options)
353
+ end
354
+
355
+ # Add a endowment ordinance
356
+ #
357
+ # ====Params
358
+ # * <tt>options</tt> - accepts a :date, :place, and :temple option
359
+ #
360
+ # ====Example
361
+ #
362
+ # person.add_endowment :date => '14 Aug 2009', :temple => 'SGEOR', :place => 'Salt Lake City, Utah'
363
+ def add_endowment(options)
364
+ add_assertions!
365
+ options[:type] = 'Endowment'
366
+ assertions.add_ordinance(options)
367
+ end
368
+
369
+ # Add a sealing to parents ordinance
370
+ #
371
+ # ====Params
372
+ # * <tt>options</tt> - accepts a :date, :place, :temple, :mother, and :father option
373
+ #
374
+ # ====Example
375
+ #
376
+ # person.add_sealing_to_parents :date => '14 Aug 2009', :temple => 'SGEOR', :place => 'Salt Lake City, Utah'
377
+ def add_sealing_to_parents(options)
378
+ raise ArgumentError, ":mother option is required" if options[:mother].nil?
379
+ raise ArgumentError, ":father option is required" if options[:father].nil?
380
+ add_assertions!
381
+ options[:type] = OrdinanceType::Sealing_to_Parents
382
+ assertions.add_ordinance(options)
383
+ end
384
+
385
+ # This method should really only be called from FamilytreeV2::Communicator#write_relationships
386
+ #
387
+ # ====Params
388
+ # * <tt>options</tt> - requires the following:
389
+ # * :type - 'parent', 'child', 'spouse'
390
+ # * :with - ID of the person with whom you are making the relationship
391
+ # * :lineage (optional) - 'Biological', 'Adoptive', etc.
392
+ # * :event - a hash with values {:type => 'Marriage', :date => '15 Nov 2007', :place => 'Utah, United States'}
393
+ def create_relationship(options)
394
+ raise ArgumentError, ":type option is required" if options[:type].nil?
395
+ raise ArgumentError, ":with option is required" if options[:with].nil?
396
+ add_relationships!
397
+ self.relationships.add_relationship(options)
398
+ end
399
+
400
+ # This method should only be called from FamilytreeV2::Communicator#combine
401
+ #
402
+ # ====Params
403
+ # * <tt>persons</tt> - an array of person objects. All persons must have an id and version
404
+ def create_combine(persons)
405
+ self.personas = Org::Familysearch::Ws::Familytree::V2::Schema::PersonPersonas.new
406
+ self.personas.personas = persons.map do |person|
407
+ persona = Org::Familysearch::Ws::Familytree::V2::Schema::PersonPersona.new
408
+ persona.id = person.id
409
+ persona.version = person.version
410
+ persona
411
+ end
412
+ end
413
+
414
+ def father_id
415
+ parent_id('Male')
416
+ end
417
+
418
+ def mother_id
419
+ parent_id('Female')
420
+ end
421
+
422
+ def spouse_id
423
+ if families && families[0] && families[0].parents
424
+ spouse_ref = families[0].parents.find{|p|p.id != self.id}
425
+ spouse_ref.id if spouse_ref
426
+ end
427
+ end
428
+
429
+ private
430
+
431
+ def parent_id(gender)
432
+ if parents && parents[0]
433
+ parent_ref = parents[0].parents.find{|p|p.gender == gender}
434
+ parent_ref.id if parent_ref
435
+ end
436
+ end
437
+
438
+ def add_parents!
439
+ self.parents ||= []
440
+ end
441
+
442
+ def add_families!
443
+ self.families ||= []
444
+ end
445
+
446
+ def add_relationships!
447
+ self.relationships ||= PersonRelationships.new
448
+ end
449
+
450
+ def add_assertions!
451
+ if assertions.nil?
452
+ self.assertions = PersonAssertions.new
453
+ end
454
+ end
455
+
456
+ def select_events(type)
457
+ if assertions && assertions.events
458
+ assertions.events.select{|e| e.value.type == type}
459
+ else
460
+ []
461
+ end
462
+ end
463
+
464
+ def select_spouse_events(type,for_person)
465
+ spouse = relationships.spouses.find{|s|s.requestedId=for_person}
466
+ if spouse.assertions && spouse.assertions.events
467
+ spouse.assertions.events.select{|e| e.value.type == type}
468
+ else
469
+ []
470
+ end
471
+ end
472
+
473
+ def select_ordinances(type)
474
+ if assertions && assertions.ordinances
475
+ assertions.ordinances.select{|e| e.value.type == type}
476
+ else
477
+ []
478
+ end
479
+ end
480
+
481
+ # only ordinance type is Sealing_to_Spouse
482
+ def select_relationship_ordinances(options)
483
+ raise ArgumentError, ":id required" if options[:id].nil?
484
+ if self.relationships
485
+ spouse_relationship = self.relationships.spouses.find{|s|s.id == options[:id]}
486
+ if spouse_relationship && spouse_relationship.assertions && spouse_relationship.assertions.ordinances
487
+ spouse_relationship.assertions.ordinances
488
+ else
489
+ []
490
+ end
491
+ end
492
+ end
493
+
494
+ end
495
+ end