summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-10-25 01:26:20 +1100
committerSzymon Szukalski <szymon@skas.io>2024-10-25 01:26:20 +1100
commit2ae1a8a2b289f010b31bcc34b54d7c7b51a2afb8 (patch)
tree3c368267392b0e0b5ce047d176d83e0080022ba7 /lib
parentcb011a691c32690e6d925fe960bed989cdac5aeb (diff)
Refactor uncle and aunt relationship handling to support both paternal and maternal sides.
Diffstat (limited to 'lib')
-rw-r--r--lib/family_tree.rb40
1 files changed, 18 insertions, 22 deletions
diff --git a/lib/family_tree.rb b/lib/family_tree.rb
index ec72d8e..0c9ecef 100644
--- a/lib/family_tree.rb
+++ b/lib/family_tree.rb
@@ -95,10 +95,10 @@ class FamilyTree
end
end
- def handle_uncle_relationship(child_of_family, type)
+ def handle_sibling_relationship(child_of_family, type, side)
return 'NONE' if child_of_family.nil?
- parent = type == 'paternal' ? child_of_family.father : child_of_family.mother
+ parent = side == 'paternal' ? child_of_family.father : child_of_family.mother
return 'NONE' if parent.nil? || parent.is_a?(NilPerson)
# Find the family where the parent is a child
@@ -110,29 +110,25 @@ class FamilyTree
# Find the siblings of the parent
siblings = find_siblings(parent_family, parent.name)
- # Select male siblings (uncles)
- uncles = siblings.select { |sibling| sibling.gender == Gender::MALE }
- uncles.empty? ? 'NONE' : uncles.map(&:name).join(' ')
+ # Select based on sibling gender
+ relatives = case type
+ when 'uncle'
+ siblings.select { |sibling| sibling.gender == Gender::MALE }
+ when 'aunt'
+ siblings.select { |sibling| sibling.gender == Gender::FEMALE }
+ else
+ []
+ end
+
+ relatives.empty? ? 'NONE' : relatives.map(&:name).join(' ')
end
- def handle_aunt_relationship(child_of_family, type)
- return 'NONE' if child_of_family.nil?
-
- parent = type == 'paternal' ? child_of_family.father : child_of_family.mother
- return 'NONE' if parent.nil? || parent.is_a?(NilPerson)
-
- # Find the family where the parent is a child
- parent_result = find_person_in_families(parent.name)
- parent_family = parent_result[:child_of_family]
-
- return 'NONE' if parent_family.nil?
-
- # Find the siblings of the parent
- siblings = find_siblings(parent_family, parent.name)
+ def handle_uncle_relationship(child_of_family, type)
+ handle_sibling_relationship(child_of_family, 'uncle', type)
+ end
- # Select female siblings (aunts)
- aunts = siblings.select { |sibling| sibling.gender == Gender::FEMALE }
- aunts.empty? ? 'NONE' : aunts.map(&:name).join(' ')
+ def handle_aunt_relationship(child_of_family, type)
+ handle_sibling_relationship(child_of_family, 'aunt', type)
end
def handle_sister_in_law_relationship(person, child_of_family)