Module: Genealogy::IneligibleMethods

Extended by:
ActiveSupport::Concern
Includes:
Constants
Defined in:
lib/genealogy/ineligible_methods.rb

Overview

Module IneligibleMethods provides methods to run genealogy queries to retrive groups of individuals who cannot be relatives according to provided role. It's included by the genealogy enabled AR model

Constant Summary

Constants included from Constants

Constants::AKA, Constants::DEFAULTS, Constants::LINEAGE2PARENT, Constants::OFF, Constants::OPPOSITESEX, Constants::PARENT2LINEAGE, Constants::PARENT2SEX, Constants::PEDIGREE, Constants::PEDIGREE_AND_DATES, Constants::SEX2PARENT

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_method_ineligible_grandparent_with_docs(lineage, parent_role, grandparent2parent_role, unexpected_sex) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/genealogy/ineligible_methods.rb', line 39

def self.generate_method_ineligible_grandparent_with_docs(lineage,parent_role,grandparent2parent_role,unexpected_sex)
  relationship = "#{lineage}_grand#{grandparent2parent_role}"
  define_method "ineligible_#{relationship}s" do
    unless send(relationship)
      ineligibles = []
      if parent = send(parent_role)          
        ineligibles |= parent.send("ineligible_#{grandparent2parent_role}s")
      elsif gclass.ineligibility_level >= PEDIGREE
        ineligibles |= descendants | siblings | [self] | gclass.send("#{unexpected_sex}s")
        if gclass.ineligibility_level >= PEDIGREE_AND_DATES              
          ineligibles |= (gclass.all - ineligibles).find_all do |indiv|
            !indiv.can_procreate_during?(send("#{parent_role}_birth_range"))
          end
        end
      end
      ineligibles
    end
  end
end

.generate_method_ineligibles_parent_with_docs(parent_role, unexpected_sex) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/genealogy/ineligible_methods.rb', line 15

def self.generate_method_ineligibles_parent_with_docs(parent_role,unexpected_sex)
  define_method "ineligible_#{parent_role}s" do
    unless self.send(parent_role) 
      ineligibles = []
      ineligibles |= descendants | [self] | gclass.send("#{unexpected_sex}s") if gclass.ineligibility_level >= PEDIGREE
      if gclass.ineligibility_level >= PEDIGREE_AND_DATES  and birth_range
        ineligibles |= (gclass.all - ineligibles).find_all do |indiv|
          !indiv.can_procreate_during?(birth_range)
        end
      end
      ineligibles
    end
  end
end

Instance Method Details

#ineligible_childrenArray

list of individual who cannot be children according to the ineligibility level in use. At `:pedigree` level it returns `self` along with their ancestors, children, full siblings and all individuals that already have father (if male) or mother (if female). At `:pedigree_and_dates` level it also includes all individuals who was born outside `self`'s fertility range, if estimable.

Returns:

  • (Array)

68
69
70
71
72
73
74
75
# File 'lib/genealogy/ineligible_methods.rb', line 68

def ineligible_children
  ineligibles = []
  ineligibles |= ancestors | children | siblings | [self] | gclass.all_with(SEX2PARENT[ssex]) if gclass.ineligibility_level >= PEDIGREE
  if gclass.ineligibility_level >= PEDIGREE_AND_DATES and fertility_range
    ineligibles |= (gclass.all - ineligibles).find_all{ |indiv| !can_procreate_during?(indiv.birth_range)}
  end
  ineligibles
end

#ineligible_fathersArray, NilClass

list of individual who cannot be father according to the ineligibility level in use. At `:pedigree` level it returns `self` along with their descendants and all females. At `:pedigree_and_dates` level it also includes all individuals who were not fertile during `self`'s estimated birth period.

Returns:

  • (Array, NilClass)

    Return nil if father already assigned


29
# File 'lib/genealogy/ineligible_methods.rb', line 29

generate_method_ineligibles_parent_with_docs(:father, :female)

#ineligible_maternal_grandfathersArray, NilClass

list of individual who cannot be maternal grandfather according to the ineligibility level in use. If `self`'s mother is known, it returns mother's ineligible fathers. Otherwise, at `:pedigree` level it returns `self` along with descendants, full siblings and all females. At `:pedigree_and_dates` level it also includes all individuals who were not fertile during `self`'s mother estimated birth period.

Returns:

  • (Array, NilClass)

    Return nil if maternal grandfather already assigned


61
# File 'lib/genealogy/ineligible_methods.rb', line 61

generate_method_ineligible_grandparent_with_docs(:maternal,:mother,:father, :female)

#ineligible_maternal_grandmothersArray, NilClass

list of individual who cannot be maternal grandmother according to the ineligibility level in use. If `self`'s mother is known, it returns mother's ineligible mothers. Otherwise, at `:pedigree` level it returns `self` along with descendants, full siblings and all males. At `:pedigree_and_dates` level it also includes all individuals who were not fertile during `self`'s mother estimated birth period.

Returns:

  • (Array, NilClass)

    Return nil if maternal grandmother already assigned


62
# File 'lib/genealogy/ineligible_methods.rb', line 62

generate_method_ineligible_grandparent_with_docs(:maternal,:mother,:mother, :male)

#ineligible_mothersArray, NilClass

list of individual who cannot be mother according to the ineligibility level in use. At `:pedigree` level it returns `self` along with their descendants and all males. At `:pedigree_and_dates` level it also includes all individuals who were not fertile during `self`'s estimated birth period.

Returns:

  • (Array, NilClass)

    Return nil if mother already assigned


30
# File 'lib/genealogy/ineligible_methods.rb', line 30

generate_method_ineligibles_parent_with_docs(:mother, :male)

#ineligible_paternal_grandfathersArray, NilClass

list of individual who cannot be paternal grandfather according to the ineligibility level in use. If `self`'s father is known, it returns father's ineligible fathers. Otherwise, at `:pedigree` level it returns `self` along with descendants, full siblings and all females. At `:pedigree_and_dates` level it also includes all individuals who were not fertile during `self`'s father estimated birth period.

Returns:

  • (Array, NilClass)

    Return nil if paternal grandfather already assigned


59
# File 'lib/genealogy/ineligible_methods.rb', line 59

generate_method_ineligible_grandparent_with_docs(:paternal,:father,:father, :female)

#ineligible_paternal_grandmothersArray, NilClass

list of individual who cannot be paternal grandmother according to the ineligibility level in use. If `self`'s father is known, it returns father's ineligible mothers. Otherwise, at `:pedigree` level it returns `self` along with descendants, full siblings and all males. At `:pedigree_and_dates` level it also includes all individuals who were not fertile during `self`'s father estimated birth period.

Returns:

  • (Array, NilClass)

    Return nil if paternal grandmother already assigned


60
# File 'lib/genealogy/ineligible_methods.rb', line 60

generate_method_ineligible_grandparent_with_docs(:paternal,:father,:mother, :male)

#ineligible_siblingsArray

list of individual who cannot be siblings according to the ineligibility level in use. At `:pedigree` level it returns `self` along with their full siblings, ancestors, descendants and all individuals with different father or mother. At `:pedigree_and_dates` level it also includes all individuals who cannot be siblings for age reasons. For each parent, if it is known it includes parent's ineligible children, otherwise it tries to estimate parent's fertility period: if it's possible it includes all individuals whose estimated birth period doesn't overlap parent's fertility period.

Returns:

  • (Array)

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/genealogy/ineligible_methods.rb', line 82

def ineligible_siblings
  ineligibles = []
  if gclass.ineligibility_level >= PEDIGREE
    ineligibles |= ancestors | descendants | siblings | [self]
    ineligibles |= (father ? gclass.all_with(:father).where("father_id != ?", father) : [])
    ineligibles |= (mother ? gclass.all_with(:mother).where("mother_id != ?", mother) : [])
  end
  if gclass.ineligibility_level >= PEDIGREE_AND_DATES 
    [:father,:mother].each do |parent|
      if p = send(parent)        # if a parent is present ineligible siblings are parent's ineligible children

        ineligibles |= p.ineligible_children
      elsif parent_fertility_range = send("#{parent}_fertility_range")        # if it's possible to estimate parent's fertility period

        remainings = gclass.all - ineligibles        # includes all individuals whose estimated birth period doesn't overlap parent's fertility period

        ineligibles |= remainings.find_all do |indiv|
          if ibr = indiv.birth_range
            !parent_fertility_range.overlaps? ibr
          else
            false
          end
        end
      end
    end
  else
  end
  ineligibles
end