Module: Genealogy::IneligibleMethods

Extended by:
ActiveSupport::Concern
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

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


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

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 >= gclass::PEDIGREE
        ineligibles |= descendants | siblings | [self] | gclass.send("#{unexpected_sex}s")
        if gclass.ineligibility_level >= gclass::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_half_siblings_with_docs(lineage, parent_role) ⇒ Object


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/genealogy/ineligible_methods.rb', line 116

def self.generate_method_ineligibles_half_siblings_with_docs(lineage,parent_role)
  define_method "ineligible_#{lineage}_half_siblings" do
    ineligibles = []
    parent = gclass::LINEAGE2PARENT[lineage]
    p = send(parent)
    if gclass.ineligibility_level >= gclass::PEDIGREE
      ineligibles |= p.ineligible_children
      ineligibles |= send("#{gclass::OPPOSITELINEAGE[lineage]}_half_siblings") # other lineage half siblings would become full siblings so they cannot be current lineage half sibling
      ineligibles |= gclass.all_with(parent)
    end
    if gclass.ineligibility_level >= gclass::PEDIGREE_AND_DATES
      if p
        # 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
    ineligibles

  end
end

.generate_method_ineligibles_parent_with_docs(parent_role, unexpected_sex) ⇒ Object


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

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 >= gclass::PEDIGREE
      if gclass.ineligibility_level >= gclass::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)

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

def ineligible_children
  ineligibles = []
  ineligibles |= ancestors | children | siblings | [self] | gclass.all_with(gclass::SEX2PARENT[ssex]) if gclass.ineligibility_level >= gclass::PEDIGREE
  if gclass.ineligibility_level >= gclass::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


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

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


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

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


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

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

#ineligible_maternal_half_siblingsArray

list of individual who cannot be maternal half_sibling according to the ineligibility level in use. At `:pedigree` level it returns mother ineligible children, other lineage halfsiblings and all individuals with mother set At `:pedigree_and_dates` level it also includes all individuals who cannot be siblings for age reasons. If mother is known it includes mother's ineligible children, otherwise it tries to estimate mother's fertility period: if it's possible it includes all individuals whose estimated birth period doesn't overlap mother's fertility period.

Returns:

  • (Array)

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

generate_method_ineligibles_half_siblings_with_docs(:maternal, :mother)

#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


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

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


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

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


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

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

#ineligible_paternal_half_siblingsArray

list of individual who cannot be paternal half_sibling according to the ineligibility level in use. At `:pedigree` level it returns father ineligible children, other lineage halfsiblings and all individuals with father set At `:pedigree_and_dates` level it also includes all individuals who cannot be siblings for age reasons. If father is known it includes father's ineligible children, otherwise it tries to estimate father's fertility period: if it's possible it includes all individuals whose estimated birth period doesn't overlap father's fertility period.

Returns:

  • (Array)

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

generate_method_ineligibles_half_siblings_with_docs(:paternal, :father)

#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)

80
81
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
# File 'lib/genealogy/ineligible_methods.rb', line 80

def ineligible_siblings
  ineligibles = []
  if gclass.ineligibility_level >= gclass::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 >= gclass::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
  end
  ineligibles
end