Skip to content

Commit

Permalink
Refactor Gedcom::Individual::relationship to not call ->father and ->…
Browse files Browse the repository at this point in the history
…mother so often
  • Loading branch information
nigelhorne committed Nov 20, 2024
1 parent d98d3bd commit c4f642c
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions gedcom
Original file line number Diff line number Diff line change
Expand Up @@ -8815,31 +8815,38 @@ sub Gedcom::Individual::possessive
# FIXME: currently only finds ancestors
# TODO: find in-laws
# See http://www.myrelative.com/html/relationship.html for inspiration
sub Gedcom::Individual::relationship {
my $self = shift;
my $other = shift;
sub Gedcom::Individual::relationship
{
my ($self, $other) = @_;

# Return undefined if both individuals are the same
return if($other->xref() eq $self->xref());

if($self->mother() && $other->mother() && $self->father() && $other->father()) {
# Retrieve parent's xref details
# Check if both individuals have complete parental information
if((my $self_mother = $self->mother()) && (my $self_father = $self->father()) &&
(my $other_mother = $other->mother()) && (my $other_father = $other->father())) {
my $sex = $other->sex() || get_value({ person => $other, value => 'sex' });
if(($self->mother()->xref() eq $other->mother()->xref()) && ($self->father()->xref() eq $other->father()->xref())) {
if($language eq 'Farsi') {
# return ($sex eq 'M') ? 'barādar' : 'khāhar';
return ($sex eq 'M') ? "\N{U+0631}\N{U+062F}\N{U+0637}\N{U+0631}\N{U+0638}" : "khāhar\N{U+0631}\N{U+0647}\N{U+0627}\N{U+0648}\N{U+062E}";
}
return i18n(($sex eq 'M') ? 'brother' : 'sister');

# Full siblings
if(($self_mother->xref() eq $other_mother->xref()) && ($self_father->xref() eq $other_father->xref())) {
# return ($sex eq 'M') ? 'barādar' : 'khāhar';
return $language eq 'Farsi'
? ($sex eq 'M' ? "\N{U+0631}\N{U+062F}\N{U+0637}\N{U+0631}\N{U+0638}" : "\N{U+062E}\N{U+0627}\N{U+0647}\N{U+0631}")
: i18n($sex eq 'M' ? 'brother' : 'sister');
}
if(($self->mother()->xref() eq $other->mother()->xref()) || ($self->father()->xref() eq $other->father()->xref())) {
if($language eq 'Latin') {
return ($sex eq 'M') ? 'frāter uterīnus' : 'soror uterīna';
} elsif($language eq 'German') {
return ($sex eq 'M') ? 'Halbbruder' : 'Halbschwester';
}
return ($sex eq 'M') ? 'half-brother' : 'half-sister';

# Half siblings
if(($self_mother->xref() eq $other_mother->xref()) || ($self_father->xref() eq $other_father->xref())) {
return $language eq 'Latin'
? ($sex eq 'M' ? 'frāter uterīnus' : 'soror uterīna')
: $language eq 'German'
? ($sex eq 'M' ? 'Halbbruder' : 'Halbschwester')
: ($sex eq 'M' ? 'half-brother' : 'half-sister');
}
}

# Fall back to relationship up or down
return $self->relationship_down($other) || $self->relationship_up($other);
}

Expand Down

0 comments on commit c4f642c

Please sign in to comment.