lib/ruby-fs-stack/familytree.rb in ruby-fs-stack-0.3.0 vs lib/ruby-fs-stack/familytree.rb in ruby-fs-stack-0.3.2
- old
+ new
@@ -50,11 +50,11 @@
url = Base + 'person'
else
url = Base + 'person/' + id
end
end
- url += "?"+FsUtils.querystring_from_hash(options) unless options.empty?
+ url += add_querystring(options)
response = @fs_communicator.get(url)
familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(response.body)
if multiple_ids
return familytree.persons
else
@@ -80,11 +80,11 @@
# ====Params
# <tt>search_params</tt> - A hash of search parameters matching API doc
def search(search_params)
url = Base + 'search'
- url += "?" + FsUtils.querystring_from_hash(search_params) unless search_params.empty?
+ url += add_querystring(search_params)
response = @fs_communicator.get(url)
familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(response.body)
# require 'pp'
# pp familytree
familytree.searches[0]
@@ -104,11 +104,11 @@
id = nil
params_hash = id_or_hash
else
raise ArgumentError, "first parameter must be a kind of String or Hash"
end
- url += "?" + FsUtils.querystring_from_hash(params_hash) unless params_hash.empty?
+ url += add_querystring(params_hash) #"?" + FsUtils.querystring_from_hash(params_hash) unless params_hash.empty?
response = @fs_communicator.get(url)
familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(response.body)
# require 'pp'
# pp familytree
familytree.matches[0]
@@ -150,11 +150,11 @@
with_id = options[relationship_type.to_sym]
url = "#{Base}person/#{base_id}/#{relationship_type}/#{with_id}"
# Get the existing person/relationship or create a new person
- unless person = relationship(base_id,options)
+ unless person = relationship(base_id,options.merge({:events => 'none'}))
person = Org::Familysearch::Ws::Familytree::V2::Schema::Person.new
person.id = base_id
end
# Add the relationship to the person with all of the correct options
@@ -175,11 +175,13 @@
return person
end
# ====Params
# * <tt>base_id</tt> - The root person for creating the relationship
- # * <tt>options</tt> - Should include either :parent, :spouse, or :child. :lineage and :event is optional
+ # * <tt>options</tt> - Should include either :parent, :spouse, or :child. :lineage and :event is optional.
+ # Other Relationship Read parameters may be included in options such as :events => 'all',
+ # :characteristics => 'all', etc.
#
# If the :lineage is set, the parent-child relationships will be written via a characteristic.
# Otherwise, an exists assertion will be created to just establish the relationship.
# ====Example
#
@@ -188,10 +190,11 @@
def relationship(base_id,options)
begin
r_type = get_relationship_type(options)
with_id = options[r_type.to_sym]
url = "#{Base}person/#{base_id}/#{r_type}/#{with_id}"
+ url += add_querystring(options)
res = @fs_communicator.get(url)
familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(res.body)
person = familytree.persons.find{|p|p.id == base_id}
return person
rescue RubyFsStack::NotFound
@@ -220,10 +223,15 @@
def get_relationship_type(options)
keys = options.keys.collect{|k|k.to_s}
key = keys.find{|k| ['parent','child','spouse'].include? k}
key
end
+
+ def add_querystring(options)
+ params = options.reject{|k,v| ['parent','child','spouse','lineage','event'].include? k.to_s }
+ (params.empty?) ? '' : "?" + FsUtils.querystring_from_hash(params)
+ end
end
end
# Mix in the module so that the fs_familytree_v1 can be called
@@ -290,10 +298,16 @@
class NameAssertion
def add_value(value)
self.value = NameValue.new
self.value.add_form(value)
end
+
+ def select(value_id)
+ self.action = 'Select'
+ self.value = AssertionValue.new
+ self.value.id = value_id
+ end
end
class EventValue
def add_date(value)
self.date = GenDate.new
@@ -319,10 +333,17 @@
self.value.type = options[:type]
self.value.add_date(options[:date]) if options[:date]
self.value.add_place(options[:place]) if options[:place]
end
+ def select(type,value_id)
+ self.value = EventValue.new
+ self.value.id = value_id
+ self.value.type = type
+ self.action = 'Select'
+ end
+
# To make porting code from v1 to v2 easier, date will reference
# value.date
def date
value.date
end
@@ -414,24 +435,39 @@
self.names ||= []
n = NameAssertion.new
n.add_value(value)
self.names << n
end
+
+ def select_name(value_id)
+ self.names ||= []
+ n = NameAssertion.new
+ n.select(value_id)
+ self.names << n
+ end
def add_event(options)
self.events ||= []
e = EventAssertion.new
e.add_value(options)
self.events << e
end
+ def select_event_summary(type,value_id)
+ self.events ||= []
+ e = EventAssertion.new
+ e.select(type,value_id)
+ self.events << e
+ end
+
def add_ordinance(options)
self.ordinances ||= []
o = OrdinanceAssertion.new
o.add_value(options)
self.ordinances << o
end
+
end
class CharacteristicAssertion
# ====Params
# * <tt>options</tt> - same as RelationshipAssertions#add_characteristic
@@ -527,10 +563,26 @@
def add_assertions!
self.assertions ||= RelationshipAssertions.new
end
end
+ class ParentsReference
+ def select_parent(parent_id, gender)
+ add_parents!
+ self.action = 'Select'
+ parent = PersonReference.new
+ parent.gender = gender
+ parent.id = parent_id
+ self.parents << parent
+ end
+
+ private
+ def add_parents!
+ self.parents ||= []
+ end
+ end
+
class PersonRelationships
def initialize
@parents = []
@spouses = []
@children = []
@@ -663,10 +715,27 @@
def add_name(value)
add_assertions!
assertions.add_name(value)
end
+ # Select the name for the summary view. This should be called on a Person record that
+ # contains a person id and version.
+ #
+ # ====Params
+ # <tt>value_id</tt> - the value id of a name assertion that you would like to set as the summary
+ #
+ # ===Example
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
+ # person.select_name_summary('1000134')
+ # com.familytree_v2.save_person person
+ #
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
+ def select_name_summary(value_id)
+ add_assertions!
+ assertions.select_name(value_id)
+ end
+
def births
select_events('Birth')
end
# It should return the selected birth assertion unless it is
@@ -700,10 +769,27 @@
def add_birth(options)
add_assertions!
options[:type] = 'Birth'
assertions.add_event(options)
end
+
+ # Select the birth for the summary view. This should be called on a Person record that
+ # contains a person id and version.
+ #
+ # ====Params
+ # <tt>value_id</tt> - the value id of a birth assertion that you would like to set as the summary
+ #
+ # ===Example
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
+ # person.select_birth_summary('1000134')
+ # com.familytree_v2.save_person person
+ #
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
+ def select_birth_summary(value_id)
+ add_assertions!
+ assertions.select_event_summary('Birth',value_id)
+ end
# Add an event with type of Birth
#
# ====Params
# * <tt>options</tt> - accepts a :date and :place option
@@ -715,10 +801,73 @@
add_assertions!
options[:type] = 'Death'
assertions.add_event(options)
end
+ # Select the death for the summary view. This should be called on a Person record that
+ # contains a person id and version.
+ #
+ # ====Params
+ # <tt>value_id</tt> - the value id of a death assertion that you would like to set as the summary
+ #
+ # ===Example
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
+ # person.select_death_summary('1000134')
+ # com.familytree_v2.save_person person
+ #
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
+ def select_death_summary(value_id)
+ add_assertions!
+ assertions.select_event_summary('Death',value_id)
+ end
+
+ # Select the mother for the summary view. This should be called on a Person record that
+ # contains a person id and version.
+ #
+ # Make sure you set both the mother and father before saving the person. Otherwise you will
+ # set a single parent as the summary.
+ #
+ # ====Params
+ # <tt>person_id</tt> - the person id of the mother that you would like to set as the summary
+ #
+ # ===Example
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
+ # person.select_mother_summary('KWQS-BBQ')
+ # person.select_father_summary('KWQS-BBT')
+ # com.familytree_v2.save_person person
+ #
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
+ def select_mother_summary(person_id)
+ add_parents!
+ couple = parents[0] || ParentsReference.new
+ couple.select_parent(person_id,'Female')
+ parents << couple
+ end
+
+ # Select the father for the summary view. This should be called on a Person record that
+ # contains a person id and version.
+ #
+ # Make sure you set both the mother and father before saving the person. Otherwise you will
+ # set a single parent as the summary.
+ #
+ # ====Params
+ # <tt>person_id</tt> - the person id of the father that you would like to set as the summary
+ #
+ # ===Example
+ # person = com.familytree_v2.person 'KWQS-BBR', :names => 'none', :genders => 'none', :events => 'none'
+ # person.select_father_summary('KWQS-BBQ')
+ # person.select_mother_summary('KWQS-BBT')
+ # com.familytree_v2.save_person person
+ #
+ # This is the recommended approach, to start with a "Version" person (no names, genders, or events)
+ def select_father_summary(person_id)
+ add_parents!
+ couple = parents[0] || ParentsReference.new
+ couple.select_parent(person_id,'Male')
+ parents << couple
+ end
+
def baptisms
select_ordinances('Baptism')
end
def confirmations
@@ -841,9 +990,13 @@
persona
end
end
private
+
+ def add_parents!
+ self.parents ||= []
+ end
def add_relationships!
self.relationships ||= PersonRelationships.new
end
\ No newline at end of file