genealogy 2.0.2 → 2.1.1

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
  SHA1:
3
- metadata.gz: fdf7cbe432225d76eb4038f8ef6cfc11187614d1
4
- data.tar.gz: 7320907b67ee1429f362b64ae2d0a725d89c0860
3
+ metadata.gz: 471eb61c7e2d5e29edac1c8796a0f35ab53d9405
4
+ data.tar.gz: ae2209d3c81a59f012649877ad9678eff6b4ddd4
5
5
  SHA512:
6
- metadata.gz: b817085d638f75df6a32f17de986e8483482b4a420ef8e7582f6fd456530a48049c8f4bb930f02730e6e0b1c348fb830294b4e69f4ab9e8fd89d3c774c36cecc
7
- data.tar.gz: 4fbf968ff2b4adf48adefaa9b0bb905abd0f37d26e8d42e5974f721d8bfc8240365e0c35e17285f1843b45f723ea30d2fbd5f4ec4137ff23d561e2e69858c861
6
+ metadata.gz: 4fe4635b6ad80fe2cbd6dfb6d6fb1c8740e7bb9c8e429e8aac7fb82231c3e1520c9d19a10587f6e0485d984030cfde9e6f625f5b94cc303a0b82b9c20aae0700
7
+ data.tar.gz: ff633aa6af193a025ae015edbaca533956b8e2fa2f391640bd213aacb08ecaccc00bfebf27d654b516cf053bb5f44b8efa09de049f22357b0c5474376b1cc2b9
@@ -6,57 +6,48 @@ module Genealogy
6
6
 
7
7
  include Constants
8
8
 
9
- # @!macro [attach] generate
9
+ # @!macro [attach] generate_method_ineligibles_parent_with_docs
10
10
  # @method ineligible_$1s
11
- # list of individual who cannot be $1
12
- # @return [Array,NilClass] Return nil if $1 already assigned
13
- def self.generate_method_ineligibles_parent(parent)
14
- define_method "ineligible_#{parent}s" do
15
- unless self.send(parent)
11
+ # list of individual who cannot be $1 according to the ineligibility level in use.
12
+ # At `:pedigree` level it returns `self` along with their descendants and all $2s.
13
+ # At `:pedigree_and_dates` level it also includes all individuals who were not fertile during `self`'s estimated birth period.
14
+ # @return [Array, NilClass] Return nil if $1 already assigned
15
+ def self.generate_method_ineligibles_parent_with_docs(parent_role,unexpected_sex)
16
+ define_method "ineligible_#{parent_role}s" do
17
+ unless self.send(parent_role)
16
18
  ineligibles = []
17
- ineligibles |= descendants | [self] | gclass.send("#{OPPOSITESEX[PARENT2SEX[parent]]}s") if gclass.ineligibility_level >= PEDIGREE
18
- if gclass.ineligibility_level >= PEDIGREE_AND_DATES and life_range
19
+ ineligibles |= descendants | [self] | gclass.send("#{unexpected_sex}s") if gclass.ineligibility_level >= PEDIGREE
20
+ if gclass.ineligibility_level >= PEDIGREE_AND_DATES and birth_range
19
21
  ineligibles |= (gclass.all - ineligibles).find_all do |indiv|
20
- if indiv.life_range
21
- if birth
22
- !indiv.can_procreate_on?(birth)
23
- else
24
- !indiv.can_procreate_during?(life_range)
25
- end
26
- else
27
- false
28
- end
22
+ !indiv.can_procreate_during?(birth_range)
29
23
  end
30
24
  end
31
25
  ineligibles
32
26
  end
33
27
  end
34
28
  end
35
- generate_method_ineligibles_parent(:father)
36
- generate_method_ineligibles_parent(:mother)
29
+ generate_method_ineligibles_parent_with_docs(:father, :female)
30
+ generate_method_ineligibles_parent_with_docs(:mother, :male)
37
31
 
38
32
 
39
- # @!macro [attach] generate
40
- # @method ineligible_$1_grand$2(grandparent)
41
- # list of individual who cannot be $1 grand$2
42
- # @return [Array,NilClass] Return nil if $$1 grand$2 already assigned
43
- def self.generate_method_ineligible_grandparent(lineage,grandparent)
44
- relationship = "#{lineage}_grand#{grandparent}"
33
+ # @!macro [attach] generate_method_ineligible_grandparent_with_docs
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.
36
+ # Otherwise, at `:pedigree` level it returns `self` along with descendants, full siblings and all $4s.
37
+ # At `:pedigree_and_dates` level it also includes all individuals who were not fertile during `self`'s $2 estimated birth period.
38
+ # @return [Array, NilClass] Return nil if $1 grand$3 already assigned
39
+ def self.generate_method_ineligible_grandparent_with_docs(lineage,parent_role,grandparent2parent_role,unexpected_sex)
40
+ relationship = "#{lineage}_grand#{grandparent2parent_role}"
45
41
  define_method "ineligible_#{relationship}s" do
46
42
  unless send(relationship)
47
- parent = send(LINEAGE2PARENT[lineage])
48
43
  ineligibles = []
49
- ineligibles |= [parent].compact | descendants | siblings | send("#{lineage}_half_siblings") | [self] | gclass.send("#{OPPOSITESEX[PARENT2SEX[grandparent]]}s") if gclass.ineligibility_level >= PEDIGREE
50
- if gclass.ineligibility_level >= PEDIGREE_AND_DATES
51
- ineligibles |= if parent
52
- parent.send("ineligible_#{grandparent}s")
53
- else
54
- (gclass.all - ineligibles).find_all do |indiv|
55
- if indiv.life_range
56
- !indiv.can_procreate_during?(send("#{LINEAGE2PARENT[lineage]}_birth_range"))
57
- else
58
- false
59
- end
44
+ if parent = send(parent_role)
45
+ ineligibles |= parent.send("ineligible_#{grandparent2parent_role}s")
46
+ elsif gclass.ineligibility_level >= PEDIGREE
47
+ ineligibles |= descendants | siblings | [self] | gclass.send("#{unexpected_sex}s")
48
+ if gclass.ineligibility_level >= PEDIGREE_AND_DATES
49
+ ineligibles |= (gclass.all - ineligibles).find_all do |indiv|
50
+ !indiv.can_procreate_during?(send("#{parent_role}_birth_range"))
60
51
  end
61
52
  end
62
53
  end
@@ -65,12 +56,14 @@ module Genealogy
65
56
  end
66
57
  end
67
58
 
68
- generate_method_ineligible_grandparent(:paternal,:father)
69
- generate_method_ineligible_grandparent(:paternal,:mother)
70
- generate_method_ineligible_grandparent(:maternal,:father)
71
- generate_method_ineligible_grandparent(:maternal,:mother)
59
+ generate_method_ineligible_grandparent_with_docs(:paternal,:father,:father, :female)
60
+ generate_method_ineligible_grandparent_with_docs(:paternal,:father,:mother, :male)
61
+ generate_method_ineligible_grandparent_with_docs(:maternal,:mother,:father, :female)
62
+ generate_method_ineligible_grandparent_with_docs(:maternal,:mother,:mother, :male)
72
63
 
73
- # list of individual who cannot be children: ancestors, children, full siblings, theirself and all individuals with father or mother according to self's sex
64
+ # list of individual who cannot be children according to the ineligibility level in use.
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
+ # At `:pedigree_and_dates` level it also includes all individuals who was born outside `self`'s fertility range, if estimable.
74
67
  # @return [Array]
75
68
  def ineligible_children
76
69
  ineligibles = []
@@ -81,7 +74,10 @@ module Genealogy
81
74
  ineligibles
82
75
  end
83
76
 
84
- # list of individual who cannot be full siblings: ancestors, descendants, siblings, theirself and all individuals with different father or mother
77
+ # list of individual who cannot be siblings according to the ineligibility level in use.
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
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.
85
81
  # @return [Array]
86
82
  def ineligible_siblings
87
83
  ineligibles = []
@@ -91,13 +87,14 @@ module Genealogy
91
87
  ineligibles |= (mother ? gclass.all_with(:mother).where("mother_id != ?", mother) : [])
92
88
  end
93
89
  if gclass.ineligibility_level >= PEDIGREE_AND_DATES
94
- # if a parent is present ineligible siblings are parent's ineligible children, otherwise try to estimate parent birth range.
95
- # If it's possible ineligible siblings are all individuals whose life range overlaps parent birth range
96
90
  [:father,:mother].each do |parent|
97
91
  if p = send(parent)
92
+ # if a parent is present ineligible siblings are parent's ineligible children
98
93
  ineligibles |= p.ineligible_children
99
94
  elsif parent_fertility_range = send("#{parent}_fertility_range")
95
+ # if it's possible to estimate parent's fertility period
100
96
  remainings = gclass.all - ineligibles
97
+ # includes all individuals whose estimated birth period doesn't overlap parent's fertility period
101
98
  ineligibles |= remainings.find_all do |indiv|
102
99
  if ibr = indiv.birth_range
103
100
  !parent_fertility_range.overlaps? ibr
@@ -9,19 +9,19 @@ module Genealogy
9
9
  def parents
10
10
  [father,mother]
11
11
  end
12
- # @return [ActiveRecord]
12
+ # @return [ActiveRecord, NilClass]
13
13
  def paternal_grandfather
14
14
  father && father.father
15
15
  end
16
- # @return [ActiveRecord]
16
+ # @return [ActiveRecord, NilClass]
17
17
  def paternal_grandmother
18
18
  father && father.mother
19
19
  end
20
- # @return [ActiveRecord]
20
+ # @return [ActiveRecord, NilClass]
21
21
  def maternal_grandfather
22
22
  mother && mother.father
23
23
  end
24
- # @return [ActiveRecord]
24
+ # @return [ActiveRecord, NilClass]
25
25
  def maternal_grandmother
26
26
  mother && mother.mother
27
27
  end
@@ -101,7 +101,7 @@ module Genealogy
101
101
  ids = siblings(half: :father).pluck(:id) | siblings(half: :mother).pluck(:id)
102
102
  result.where(id: ids)
103
103
  when :include # including half siblings
104
- result.where("father_id == ? or mother_id == ?", father_id, mother_id)
104
+ result.where("father_id = ? or mother_id = ?", father_id, mother_id)
105
105
  else
106
106
  raise ArgumentError, "Admitted values for :half options are: :father, :mother, false, true or nil"
107
107
  end
@@ -63,14 +63,14 @@ module Genealogy
63
63
  # @param [Date] date
64
64
  # @return [Boolean] or nil if cannot be computable (#fertility_range returns nil)
65
65
  def can_procreate_on?(date)
66
- fertility_range.cover? date if date and fertility_range
66
+ fertility_range.cover? date if (date and fertility_range)
67
67
  end
68
68
 
69
69
  # It tests whether fertility range overlaps specified period
70
70
  # @param [Range] period
71
71
  # @return [Boolean] or nil if cannot be computable (#fertility_range returns nil)
72
72
  def can_procreate_during?(period)
73
- fertility_range.overlaps? period if period and fertility_range
73
+ fertility_range.overlaps? period if (period and fertility_range)
74
74
  end
75
75
 
76
76
  # @!macro [attach] generate
@@ -1,3 +1,3 @@
1
1
  module Genealogy
2
- VERSION = "2.0.2"
2
+ VERSION = "2.1.1"
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.0.2
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - masciugo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-17 00:00:00.000000000 Z
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mysql2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -244,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
272
  version: '0'
245
273
  requirements: []
246
274
  rubyforge_project: "[none]"
247
- rubygems_version: 2.4.5
275
+ rubygems_version: 2.2.2
248
276
  signing_key:
249
277
  specification_version: 4
250
278
  summary: Make ActiveRecord model act as a pedigree