genealogy 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdc120f7f9e2dcf06406a5ff6c0f9ff3e141479c30f7f25e6882003de83b6ba7
4
- data.tar.gz: a7d8e6e2842288b654795134416882dcb9f84efea646d6808b24eef3638662f3
3
+ metadata.gz: da5a494d35d958b648df8c4f1976db27abd22d9b1388cf9bdbfa82f9ff5ac92c
4
+ data.tar.gz: 75613c06ae73ff27fb53b24dc9dd867fd56e5c8b72c43ea54afb08a6d7601373
5
5
  SHA512:
6
- metadata.gz: aa770c140025e6f4a990302dcb804eed27de2c3aae987d83aefbb6c5fa7c51d4f4380f18c9194cce4a33d93c7432fc92d8d297dd38e8cc31db99a0d862ac0412
7
- data.tar.gz: b40dbcdc590f93623e1836cd2de2aa0caa3f8ad0bc383e1a5c24f0023af75f20b6ff18d69f3f278bffc96f9d54a2a08fc79c77a403515f100084937b92a2ab7c
6
+ metadata.gz: 5061aa292b318ed81e38ae9897ed4f25f6edab8a6a84d0667a50e1940269e0739000091884fa953d6948978397bd63c23695ae49d11f14fecc63c6c2c0fe1362
7
+ data.tar.gz: c794897c6484d2ebcc254a870e5456064a01e3538695ece896f2c926eff0f3928b942b9732eb0abf513d5f218310628088bc1019fbae0fb117fefe59fc462604
@@ -175,7 +175,15 @@ module Genealogy
175
175
  # @return [Boolean]
176
176
  def add_siblings(*args)
177
177
  options = args.extract_options!
178
- check_incompatible_relationship(:sibling, *args)
178
+ case options[:half]
179
+ when :father
180
+ check_incompatible_relationship(:paternal_half_sibling, *args)
181
+ when :mother
182
+ check_incompatible_relationship(:maternal_half_sibling, *args)
183
+ when nil
184
+ check_incompatible_relationship(:sibling, *args)
185
+ end
186
+
179
187
  transaction do
180
188
  args.inject(true) do |res,sib|
181
189
  res &= case options[:half]
@@ -31,6 +31,7 @@ module Genealogy
31
31
 
32
32
  PARENT2LINEAGE = ActiveSupport::HashWithIndifferentAccess.new({ father: :paternal, mother: :maternal })
33
33
  LINEAGE2PARENT = ActiveSupport::HashWithIndifferentAccess.new({ paternal: :father, maternal: :mother })
34
+ OPPOSITELINEAGE = ActiveSupport::HashWithIndifferentAccess.new({ paternal: :maternal, maternal: :paternal })
34
35
  PARENT2SEX = ActiveSupport::HashWithIndifferentAccess.new({ father: :male, mother: :female })
35
36
  SEX2PARENT = ActiveSupport::HashWithIndifferentAccess.new({ male: :father, female: :mother })
36
37
  OPPOSITESEX = ActiveSupport::HashWithIndifferentAccess.new({male: :female, female: :male})
@@ -38,18 +39,18 @@ module Genealogy
38
39
  AKA = ActiveSupport::HashWithIndifferentAccess.new({
39
40
  father: "F",
40
41
  mother: "M",
41
- paternal_grandfather: "PGF",
42
- paternal_grandmother: "PGM",
43
- maternal_grandfather: "MGF",
44
- maternal_grandmother: "MGM",
42
+ paternal_grandfather: "PGF",
43
+ paternal_grandmother: "PGM",
44
+ maternal_grandfather: "MGF",
45
+ maternal_grandmother: "MGM",
45
46
  children: "C",
46
- siblings: "S",
47
+ siblings: "S",
47
48
  half_siblings: "HS",
48
49
  paternal_half_siblings: "PHS",
49
- maternal_half_siblings: "MHS",
50
- grandchildren: "GC",
51
- uncles_and_aunts: "U&A",
50
+ maternal_half_siblings: "MHS",
51
+ grandchildren: "GC",
52
+ uncles_and_aunts: "U&A",
52
53
  nieces_and_nephews: "N&N"
53
54
  })
54
55
  end
55
- end
56
+ end
@@ -14,7 +14,7 @@ module Genealogy
14
14
  # @return [Array, NilClass] Return nil if $1 already assigned
15
15
  def self.generate_method_ineligibles_parent_with_docs(parent_role,unexpected_sex)
16
16
  define_method "ineligible_#{parent_role}s" do
17
- unless self.send(parent_role)
17
+ unless self.send(parent_role)
18
18
  ineligibles = []
19
19
  ineligibles |= descendants | [self] | gclass.send("#{unexpected_sex}s") if gclass.ineligibility_level >= PEDIGREE
20
20
  if gclass.ineligibility_level >= PEDIGREE_AND_DATES and birth_range
@@ -32,7 +32,7 @@ module Genealogy
32
32
 
33
33
  # @!macro [attach] generate_method_ineligible_grandparent_with_docs
34
34
  # @method ineligible_$1_grand$3s
35
- # list of individual who cannot be $1 grand$3 according to the ineligibility level in use. If `self`'s $2 is known, it returns $2's ineligible $3s.
35
+ # list of individual who cannot be $1 grand$3 according to the ineligibility level in use. If `self`'s $2 is known, it returns $2's ineligible $3s.
36
36
  # Otherwise, at `:pedigree` level it returns `self` along with descendants, full siblings and all $4s.
37
37
  # At `:pedigree_and_dates` level it also includes all individuals who were not fertile during `self`'s $2 estimated birth period.
38
38
  # @return [Array, NilClass] Return nil if $1 grand$3 already assigned
@@ -41,11 +41,11 @@ module Genealogy
41
41
  define_method "ineligible_#{relationship}s" do
42
42
  unless send(relationship)
43
43
  ineligibles = []
44
- if parent = send(parent_role)
44
+ if parent = send(parent_role)
45
45
  ineligibles |= parent.send("ineligible_#{grandparent2parent_role}s")
46
46
  elsif gclass.ineligibility_level >= PEDIGREE
47
47
  ineligibles |= descendants | siblings | [self] | gclass.send("#{unexpected_sex}s")
48
- if gclass.ineligibility_level >= PEDIGREE_AND_DATES
48
+ if gclass.ineligibility_level >= PEDIGREE_AND_DATES
49
49
  ineligibles |= (gclass.all - ineligibles).find_all do |indiv|
50
50
  !indiv.can_procreate_during?(send("#{parent_role}_birth_range"))
51
51
  end
@@ -55,13 +55,13 @@ module Genealogy
55
55
  end
56
56
  end
57
57
  end
58
-
58
+
59
59
  generate_method_ineligible_grandparent_with_docs(:paternal,:father,:father, :female)
60
60
  generate_method_ineligible_grandparent_with_docs(:paternal,:father,:mother, :male)
61
61
  generate_method_ineligible_grandparent_with_docs(:maternal,:mother,:father, :female)
62
62
  generate_method_ineligible_grandparent_with_docs(:maternal,:mother,:mother, :male)
63
63
 
64
- # list of individual who cannot be children according to the ineligibility level in use.
64
+ # list of individual who cannot be children according to the ineligibility level in use.
65
65
  # 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).
66
66
  # At `:pedigree_and_dates` level it also includes all individuals who was born outside `self`'s fertility range, if estimable.
67
67
  # @return [Array]
@@ -74,9 +74,9 @@ module Genealogy
74
74
  ineligibles
75
75
  end
76
76
 
77
- # list of individual who cannot be siblings according to the ineligibility level in use.
77
+ # list of individual who cannot be siblings according to the ineligibility level in use.
78
78
  # At `:pedigree` level it returns `self` along with their full siblings, ancestors, descendants and all individuals with different father or mother.
79
- # At `:pedigree_and_dates` level it also includes all individuals who cannot be siblings for age reasons. For each parent, if it is known
79
+ # At `:pedigree_and_dates` level it also includes all individuals who cannot be siblings for age reasons. For each parent, if it is known
80
80
  # 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.
81
81
  # @return [Array]
82
82
  def ineligible_siblings
@@ -86,7 +86,7 @@ module Genealogy
86
86
  ineligibles |= (father ? gclass.all_with(:father).where("father_id != ?", father) : [])
87
87
  ineligibles |= (mother ? gclass.all_with(:mother).where("mother_id != ?", mother) : [])
88
88
  end
89
- if gclass.ineligibility_level >= PEDIGREE_AND_DATES
89
+ if gclass.ineligibility_level >= PEDIGREE_AND_DATES
90
90
  [:father,:mother].each do |parent|
91
91
  if p = send(parent)
92
92
  # if a parent is present ineligible siblings are parent's ineligible children
@@ -104,10 +104,50 @@ module Genealogy
104
104
  end
105
105
  end
106
106
  end
107
- else
108
107
  end
109
108
  ineligibles
110
109
  end
111
110
 
111
+ # @!macro [attach] generate_method_ineligibles_half_siblings_with_docs
112
+ # @method ineligible_$1_half_siblings
113
+ # list of individual who cannot be $1 half_sibling according to the ineligibility level in use.
114
+ # At `:pedigree` level it returns `self` along with siblings, other lineage halfsiblngs and all individuals with differnt $2
115
+ # At `:pedigree_and_dates` level it also includes all individuals who cannot be siblings for age reasons. If $2 is known it includes $2's ineligible children,
116
+ # otherwise it tries to estimate $2's fertility period: if it's possible it includes all individuals whose estimated birth period doesn't overlap $2's fertility period.
117
+ # @return [Array]
118
+ def self.generate_method_ineligibles_half_siblings_with_docs(lineage,parent_role)
119
+ define_method "ineligible_#{lineage}_half_siblings" do
120
+ ineligibles = []
121
+ parent = LINEAGE2PARENT[lineage]
122
+ p = send(parent)
123
+ if gclass.ineligibility_level >= PEDIGREE
124
+ ineligibles |= siblings | [self,p]
125
+ ineligibles |= send("#{OPPOSITELINEAGE[lineage]}_half_siblings") # other lineage half siblings would become full siblings so they cannot be current lineage half sibling
126
+ ineligibles |= gclass.all_with(parent).where("#{parent}_id != ?", p) if p
127
+ end
128
+ if gclass.ineligibility_level >= PEDIGREE_AND_DATES
129
+ if p
130
+ # if a parent is present ineligible siblings are parent's ineligible children
131
+ ineligibles |= p.ineligible_children
132
+ elsif parent_fertility_range = send("#{parent}_fertility_range")
133
+ # if it's possible to estimate parent's fertility period
134
+ remainings = gclass.all - ineligibles
135
+ # includes all individuals whose estimated birth period doesn't overlap parent's fertility period
136
+ ineligibles |= remainings.find_all do |indiv|
137
+ if ibr = indiv.birth_range
138
+ !parent_fertility_range.overlaps? ibr
139
+ else
140
+ false
141
+ end
142
+ end
143
+ end
144
+ end
145
+ ineligibles
146
+
147
+ end
148
+ end
149
+ generate_method_ineligibles_half_siblings_with_docs(:paternal, :father)
150
+ generate_method_ineligibles_half_siblings_with_docs(:maternal, :mother)
151
+
112
152
  end
113
- end
153
+ end
@@ -1,3 +1,3 @@
1
1
  module Genealogy
2
- VERSION = "2.4.0"
2
+ VERSION = "2.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genealogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - masciugo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-03 00:00:00.000000000 Z
11
+ date: 2018-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord