summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-10-25 12:05:03 +1100
committerSzymon Szukalski <szymon@skas.io>2024-10-25 12:05:03 +1100
commit5d5ca66762513dccfbc4e76782e81bc593258c68 (patch)
tree4ad253977f23d0cb08b4d65e6895151aceb4871e /lib
parent29fe91901a188af552a0bbaeb59eaf056fbe385d (diff)
Update README and fix incorrect outputs
- Don't output anything if the relationship is unsupported - Fail if we're adding a child via the father to a family
Diffstat (limited to 'lib')
-rw-r--r--lib/action_file_executor.rb3
-rw-r--r--lib/family_tree.rb6
2 files changed, 6 insertions, 3 deletions
diff --git a/lib/action_file_executor.rb b/lib/action_file_executor.rb
index 2354dd7..701ad02 100644
--- a/lib/action_file_executor.rb
+++ b/lib/action_file_executor.rb
@@ -72,7 +72,8 @@ class ActionFileExecutor
when 'ADD_CHILD'
puts FamilyTree.instance.add_child(*params)
when 'GET_RELATIONSHIP'
- puts FamilyTree.instance.get_relationship(*params)
+ result = FamilyTree.instance.get_relationship(*params)
+ result && puts(result)
end
end
diff --git a/lib/family_tree.rb b/lib/family_tree.rb
index 5ba8c72..9850280 100644
--- a/lib/family_tree.rb
+++ b/lib/family_tree.rb
@@ -38,6 +38,8 @@ class FamilyTree
parent = result[:person]
parent_of_family = result[:parent_of_family]
+ return 'PERSON_NOT_FOUND' if parent.is_a?(NilPerson)
+
if parent_of_family.nil? || parent_of_family.mother.is_a?(NilPerson) || parent_of_family.father.eql?(parent)
return 'CHILD_ADDITION_FAILED'
end
@@ -82,7 +84,7 @@ class FamilyTree
when 'brother-in-law'
handle_brother_in_law_relationship(person, child_of_family)
else
- 'UNSUPPORTED_RELATIONSHIP'
+ false
end
end
@@ -130,7 +132,7 @@ class FamilyTree
daughters = children.select { |child| child.gender == Gender::FEMALE }
daughters.empty? ? 'NONE' : daughters.map(&:name).join(' ')
else
- 'UNSUPPORTED_RELATIONSHIP'
+ false
end
end