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/family_tree.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/family_tree.rb') 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