From 5d5ca66762513dccfbc4e76782e81bc593258c68 Mon Sep 17 00:00:00 2001 From: Szymon Szukalski Date: Fri, 25 Oct 2024 12:05:03 +1100 Subject: 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 --- lib/action_file_executor.rb | 3 ++- lib/family_tree.rb | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3