genealogy 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6a3789413a0f15b45dca9101f416f34b7b4b47c2e68c236fd83c1d3a8305077
4
- data.tar.gz: 2be53f13d7e489235efb232865fa664124b0e37ac3f3a943cee2397b8a1153c1
3
+ metadata.gz: e3dda0154052e22f243b48bae114dae17b40b405c7968dcd59c2593c62e8862a
4
+ data.tar.gz: e9d6368fe55759b49a8c67c7e45174cbe0ef94b607886036f8d5593ebe0c4101
5
5
  SHA512:
6
- metadata.gz: 23c8bec528f25388264d9ec506c04473e3d4970d34298ce0b5a03d9620f9c2373574acadb337543444d7166d96d1428ada1adef560b05ad6df2ff76fe451d5e3
7
- data.tar.gz: 4cc61c08bb91e6e58e3aafc3e25a57d765a955936e50d86d081582411bc46d26644800a48fc57f6deda18597fcddcf5703909a89f6ebc703b684ca743b266868
6
+ metadata.gz: f4bf0b82f01ca8e76631500314b288f50daa16d181c827dca08a8dbc9432f27d92da3b558a01c676b0196c072b02a880ae5aeaf3c99c851de52717759871b83f
7
+ data.tar.gz: ce491f72110f4c82be25f4a0c881195864aa418891717d5766b437a1a684502b34c9b4ba5ca257c32290f2e4c4a553cf1975517e30ab82638a94bbaf48f4ae29
@@ -7,10 +7,10 @@ module Genealogy
7
7
 
8
8
  # @!macro [attach] generate
9
9
  # @method add_$1(parent)
10
- # Add $1
10
+ # Add $1
11
11
  # @param [Object] parent
12
12
  # @raise [Exception] if perform validation is enabled and self is invalid
13
- # @return [Boolean]
13
+ # @return [Boolean]
14
14
  def self.generate_method_add_parent(parent)
15
15
  define_method "add_#{parent}" do |relative|
16
16
  check_incompatible_relationship(parent,relative)
@@ -29,7 +29,7 @@ module Genealogy
29
29
  # @method remove_$1
30
30
  # remove $1. Foreign_key set to nil
31
31
  # @raise [Exception] if perform validation is enabled and self is invalid
32
- # @return [Boolean]
32
+ # @return [Boolean]
33
33
  def self.generate_method_remove_parent(parent)
34
34
  define_method "remove_#{parent}" do
35
35
  if gclass.perform_validation_enabled
@@ -48,7 +48,7 @@ module Genealogy
48
48
  # @param [Object] mother
49
49
  # @see #add_father
50
50
  # @see #add_mother
51
- # @return [Boolean]
51
+ # @return [Boolean]
52
52
  def add_parents(father,mother)
53
53
  transaction do
54
54
  add_father(father)
@@ -59,7 +59,7 @@ module Genealogy
59
59
  # remove both parents calling #remove_father and #remove_mother in a transaction
60
60
  # @see #remove_father
61
61
  # @see #remove_mother
62
- # @return [Boolean]
62
+ # @return [Boolean]
63
63
  def remove_parents
64
64
  transaction do
65
65
  remove_father
@@ -69,10 +69,10 @@ module Genealogy
69
69
 
70
70
  # @!macro [attach] generate
71
71
  # @method add_$1_grand$2(grandparent)
72
- # Add $1 grand$2
72
+ # Add $1 grand$2
73
73
  # @param [Object] gp grandparent
74
74
  # @raise [Exception] if perform validation is enabled and self is invalid
75
- # @return [Boolean]
75
+ # @return [Boolean]
76
76
  def self.generate_method_add_grandparent(lineage,grandparent)
77
77
  relationship = "#{lineage}_grand#{grandparent}"
78
78
  define_method "add_#{relationship}" do |gp|
@@ -89,9 +89,9 @@ module Genealogy
89
89
 
90
90
  # @!macro [attach] generate
91
91
  # @method remove_$1_grand$2
92
- # remove $1 grand$2
92
+ # remove $1 grand$2
93
93
  # @raise [Exception] if perform validation is enabled and self is invalid
94
- # @return [Boolean]
94
+ # @return [Boolean]
95
95
  def self.generate_method_remove_grandparent(lineage,grandparent)
96
96
  relationship = "#{lineage}_grand#{grandparent}"
97
97
  define_method "remove_#{relationship}" do
@@ -107,11 +107,11 @@ module Genealogy
107
107
 
108
108
  # @!macro [attach] generate
109
109
  # @method add_$1_grandparents
110
- # Add $1 grandparents
110
+ # Add $1 grandparents
111
111
  # @param [Object] gf grandfather
112
112
  # @param [Object] gm grandmother
113
113
  # @raise [Exception] if perform validation is enabled and self is invalid
114
- # @return [Boolean]
114
+ # @return [Boolean]
115
115
  def self.generate_method_add_grandparents_by_lineage(lineage)
116
116
  relationship = "#{lineage}_grandparents"
117
117
  define_method "add_#{relationship}" do |gf,gm|
@@ -125,12 +125,12 @@ module Genealogy
125
125
 
126
126
  # @!macro [attach] generate
127
127
  # @method remove_$1_grandparents
128
- # remove $1 grandparents
128
+ # remove $1 grandparents
129
129
  # @raise [Exception] if perform validation is enabled and self is invalid
130
- # @return [Boolean]
130
+ # @return [Boolean]
131
131
  def self.generate_method_remove_grandparents_by_lineage(lineage)
132
132
  relationship = "#{lineage}_grandparents"
133
- define_method "remove_#{relationship}" do
133
+ define_method "remove_#{relationship}" do
134
134
  parent = LINEAGE2PARENT[lineage]
135
135
  raise_if_gap_on(parent)
136
136
  send(parent).send("remove_parents")
@@ -147,7 +147,7 @@ module Genealogy
147
147
  # @param [Object] mgm maternal grandmother
148
148
  # @see #add_paternal_grandparents
149
149
  # @see #add_maternal_grandparents
150
- # @return [Boolean]
150
+ # @return [Boolean]
151
151
  def add_grandparents(pgf,pgm,mgf,mgm)
152
152
  transaction do
153
153
  add_paternal_grandparents(pgf,pgm)
@@ -158,7 +158,7 @@ module Genealogy
158
158
  # remove all grandparents calling #remove_paternal_grandparents and #remove_maternal_grandparents in a transaction
159
159
  # @see #remove_paternal_grandparents
160
160
  # @see #remove_maternal_grandparents
161
- # @return [Boolean]
161
+ # @return [Boolean]
162
162
  def remove_grandparents
163
163
  transaction do
164
164
  remove_paternal_grandparents
@@ -172,7 +172,7 @@ module Genealogy
172
172
  # @param [Hash] options
173
173
  # @option options [Symbol] half :father for paternal half siblings and :mother for maternal half siblings
174
174
  # @option options [Object] spouse if specified, passed individual will be used as mother in case of half sibling
175
- # @return [Boolean]
175
+ # @return [Boolean]
176
176
  def add_siblings(*args)
177
177
  options = args.extract_options!
178
178
  check_incompatible_relationship(:sibling, *args)
@@ -203,8 +203,8 @@ module Genealogy
203
203
  add_siblings(sibling,options)
204
204
  end
205
205
 
206
-
207
- # remove siblings by nullifying parents of passed individuals
206
+
207
+ # remove siblings by nullifying parents of passed individuals
208
208
  # @overload remove_siblings(*siblings,options={})
209
209
  # @param [Object] siblings list of siblings
210
210
  # @param [Hash] options
@@ -230,7 +230,7 @@ module Genealogy
230
230
  sib.remove_mother
231
231
  when nil
232
232
  sib.remove_parents
233
- end
233
+ end
234
234
  end
235
235
  end
236
236
  !resulting_indivs.empty? #returned value must be true if self has at least a siblings to affect
@@ -246,21 +246,21 @@ module Genealogy
246
246
  # @param [Object] children list of children
247
247
  # @param [Hash] options
248
248
  # @option options [Object] spouse if specified, children will have that spouse
249
- # @return [Boolean]
249
+ # @return [Boolean]
250
250
  def add_children(*args)
251
251
  options = args.extract_options!
252
252
  raise_if_sex_undefined
253
253
  check_incompatible_relationship(:children, *args)
254
254
  transaction do
255
255
  args.inject(true) do |res,child|
256
- res &= case sex
256
+ res &= case sex_before_type_cast
257
257
  when gclass.sex_male_value
258
258
  child.add_mother(options[:spouse]) if options[:spouse]
259
259
  child.add_father(self)
260
260
  when gclass.sex_female_value
261
261
  child.add_father(options[:spouse]) if options[:spouse]
262
262
  child.add_mother(self)
263
- else
263
+ else
264
264
  raise SexError, "Sex value not valid for #{self}"
265
265
  end
266
266
  end
@@ -294,14 +294,14 @@ module Genealogy
294
294
  if options[:remove_other_parent] == true
295
295
  child.remove_parents
296
296
  else
297
- case sex
297
+ case sex_before_type_cast
298
298
  when gclass.sex_male_value
299
299
  child.remove_father
300
300
  when gclass.sex_female_value
301
301
  child.remove_mother
302
- else
302
+ else
303
303
  raise SexError, "Sex value not valid for #{self}"
304
- end
304
+ end
305
305
  end
306
306
  end
307
307
  end
@@ -5,28 +5,28 @@ module Genealogy
5
5
 
6
6
  include Constants
7
7
 
8
- # @return [2-elements Array] father and mother
8
+ # @return [2-elements Array] father and mother
9
9
  def parents
10
10
  [father,mother]
11
11
  end
12
- # @return [ActiveRecord, NilClass]
12
+ # @return [ActiveRecord, NilClass]
13
13
  def paternal_grandfather
14
14
  father && father.father
15
15
  end
16
- # @return [ActiveRecord, NilClass]
16
+ # @return [ActiveRecord, NilClass]
17
17
  def paternal_grandmother
18
18
  father && father.mother
19
19
  end
20
- # @return [ActiveRecord, NilClass]
20
+ # @return [ActiveRecord, NilClass]
21
21
  def maternal_grandfather
22
22
  mother && mother.father
23
23
  end
24
- # @return [ActiveRecord, NilClass]
24
+ # @return [ActiveRecord, NilClass]
25
25
  def maternal_grandmother
26
26
  mother && mother.mother
27
27
  end
28
28
 
29
- # @return [2-elements Array] paternal_grandfather and paternal_grandmother
29
+ # @return [2-elements Array] paternal_grandfather and paternal_grandmother
30
30
  def paternal_grandparents
31
31
  (father && father.parents) || [nil,nil]
32
32
  end
@@ -50,7 +50,7 @@ module Genealogy
50
50
  # @option options [Object] spouse to filter children by spouse
51
51
  # @return [ActiveRecord::Relation] children
52
52
  def children(options = {})
53
- raise SexError, "Sex value not valid for #{self}. It's needed to look for children" unless gclass.sex_values.include? sex
53
+ raise SexError, "Sex value not valid for #{self}. It's needed to look for children" unless gclass.sex_values.include? sex_before_type_cast
54
54
  result = gclass.where("#{SEX2PARENT[ssex]}_id" => self)
55
55
  if options.keys.include? :spouse
56
56
  check_indiv(spouse = options[:spouse],opposite_ssex)
@@ -79,7 +79,7 @@ module Genealogy
79
79
  result.all_with(:parents).where(father_id: father, mother_id: mother)
80
80
  when :father # common father
81
81
  result = result.all_with(:father).where(father_id: father)
82
- if spouse
82
+ if spouse
83
83
  check_indiv(spouse, :female)
84
84
  result.where(mother_id: spouse)
85
85
  elsif mother
@@ -109,7 +109,7 @@ module Genealogy
109
109
  end
110
110
 
111
111
  # siblings with option half: :only
112
- # @see #siblings
112
+ # @see #siblings
113
113
  def half_siblings(options = {})
114
114
  siblings(options.merge(half: :only))
115
115
  end
@@ -196,7 +196,7 @@ module Genealogy
196
196
  def great_grandchildren
197
197
  result = grandchildren.compact.inject([]){|memo,grandchild| memo |= grandchild.children}
198
198
  end
199
-
199
+
200
200
  # list of uncles and aunts iterating through parents' siblings
201
201
  # @param [Hash] options
202
202
  # @option options [Symbol] lineage to filter by lineage: :paternal or :maternal
@@ -275,7 +275,7 @@ module Genealogy
275
275
  # family hash with roles as keys? :spouse and individuals as values. Defaults roles are :father, :mother, :children, :siblings and current_spouse if enabled
276
276
  # @option options [Symbol] half to filter siblings (see #siblings)
277
277
  # @option options [Boolean] extended to include roles for grandparents, grandchildren, uncles, aunts, nieces, nephews and cousins
278
- # @return [Hash] family hash with roles as keys? :spouse and individuals as values.
278
+ # @return [Hash] family hash with roles as keys? :spouse and individuals as values.
279
279
  def family_hash(options = {})
280
280
  roles = [:father, :mother, :children, :siblings]
281
281
  roles += [:current_spouse] if self.class.current_spouse_enabled
@@ -303,7 +303,7 @@ module Genealogy
303
303
 
304
304
  # family individuals
305
305
  # @return [Array]
306
- # @see #family_hash
306
+ # @see #family_hash
307
307
  def family(options = {})
308
308
  hash = family_hash(options)
309
309
  hash.keys.inject([]){|tot,k| tot << hash[k] }.compact.flatten
@@ -319,17 +319,17 @@ module Genealogy
319
319
 
320
320
  module ClassMethods
321
321
  # all male individuals
322
- # @return [ActiveRecord::Relation]
322
+ # @return [ActiveRecord::Relation]
323
323
  def males
324
324
  where(sex: sex_male_value)
325
325
  end
326
326
  # all female individuals
327
- # @return [ActiveRecord::Relation]
327
+ # @return [ActiveRecord::Relation]
328
328
  def females
329
329
  where(sex: sex_female_value)
330
330
  end
331
331
  # all individuals individuals having relative with specified role
332
- # @return [ActiveRecord, ActiveRecord::Relation]
332
+ # @return [ActiveRecord, ActiveRecord::Relation]
333
333
  def all_with(role)
334
334
  case role
335
335
  when :father
@@ -344,4 +344,4 @@ module Genealogy
344
344
  end
345
345
 
346
346
  end
347
- end
347
+ end
@@ -67,7 +67,7 @@ module Genealogy
67
67
  end
68
68
 
69
69
  # It tests whether fertility range overlaps specified period
70
- # @param [Range] period
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
73
  fertility_range.overlaps? period if (period and fertility_range)
@@ -104,9 +104,9 @@ module Genealogy
104
104
  generate_method_parent_fertility_range(:mother)
105
105
 
106
106
  # sex in terms of :male or :female
107
- # @return [Symbol]
107
+ # @return [Symbol]
108
108
  def ssex
109
- case sex
109
+ case sex_before_type_cast
110
110
  when gclass.sex_male_value
111
111
  :male
112
112
  when gclass.sex_female_value
@@ -117,42 +117,42 @@ module Genealogy
117
117
  end
118
118
 
119
119
  # opposite sex in terms of :male or :female
120
- # @return [Symbol]
120
+ # @return [Symbol]
121
121
  def opposite_ssex
122
122
  OPPOSITESEX[ssex]
123
123
  end
124
124
 
125
- # @return [Boolean]
125
+ # @return [Boolean]
126
126
  def is_female?
127
127
  return female? if respond_to?(:female?)
128
- sex == gclass.sex_female_value
128
+ sex_before_type_cast == gclass.sex_female_value
129
129
  end
130
130
 
131
- # @return [Boolean]
131
+ # @return [Boolean]
132
132
  def is_male?
133
133
  return male? if respond_to?(:male?)
134
- sex == gclass.sex_male_value
134
+ sex_before_type_cast == gclass.sex_male_value
135
135
  end
136
-
136
+
137
137
  # max life expectancy in terms of years. It depends on sex
138
- # @return [Integer]
138
+ # @return [Integer]
139
139
  def max_le
140
140
  gclass.send("max_#{ssex}_life_expectancy").years
141
141
  end
142
-
142
+
143
143
  # max fertility procreation age in terms of years. It depends on sex
144
- # @return [Integer]
144
+ # @return [Integer]
145
145
  def max_fpa
146
146
  gclass.send("max_#{ssex}_procreation_age").years
147
147
  end
148
-
148
+
149
149
  # min fertility procreation age in terms of years. It depends on sex
150
- # @return [Integer]
150
+ # @return [Integer]
151
151
  def min_fpa
152
152
  gclass.send("min_#{ssex}_procreation_age").years
153
153
  end
154
154
 
155
- private
155
+ private
156
156
 
157
157
  def check_incompatible_relationship(*args)
158
158
  relationship = args.shift
@@ -200,4 +200,4 @@ module Genealogy
200
200
  end
201
201
 
202
202
  end
203
- end
203
+ end
@@ -1,3 +1,3 @@
1
1
  module Genealogy
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genealogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - masciugo