Module: Genealogy::UtilMethods
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/genealogy/util_methods.rb
Overview
Module UtilMethods provides methods to run utility methods. It's included by the genealogy enabled AR model
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
- .generate_method_parent_birth_range(parent) ⇒ Object
- .generate_method_parent_fertility_range(parent) ⇒ Object
Instance Method Summary collapse
-
#birth ⇒ Date
Genealogy thinks time in term of Date, not DateTime.
-
#birth_range ⇒ Range
optimistic (longest) estimation of birth date.
-
#can_procreate_during?(period) ⇒ Boolean
It tests whether fertility range overlaps specified period.
-
#can_procreate_on?(date) ⇒ Boolean
It tests whether fertility range covers specified date.
-
#death ⇒ Date
Genealogy thinks time in term of Date, not DateTime.
-
#father_birth_range ⇒ Range
optimistic (longest) estimation of father's birth date.
-
#father_fertility_range ⇒ Range
optimistic (longest) estimation of father's fertility range.
-
#fertility_range ⇒ Range
optimistic (longest) estimation of fertility period.
- #is_female? ⇒ Boolean
- #is_male? ⇒ Boolean
-
#life_range ⇒ Range
optimistic (longest) estimation of life period.
-
#max_fpa ⇒ Integer
max fertility procreation age in terms of years.
-
#max_le ⇒ Integer
max life expectancy in terms of years.
-
#min_fpa ⇒ Integer
min fertility procreation age in terms of years.
-
#mother_birth_range ⇒ Range
optimistic (longest) estimation of mother's birth date.
-
#mother_fertility_range ⇒ Range
optimistic (longest) estimation of mother's fertility range.
-
#opposite_ssex ⇒ Symbol
opposite sex in terms of :male or :female.
-
#ssex ⇒ Symbol
sex in terms of :male or :female.
Class Method Details
.generate_method_parent_birth_range(parent) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/genealogy/util_methods.rb', line 78 def self.generate_method_parent_birth_range(parent) define_method "#{parent}_birth_range" do if birth (birth - gclass.send("max_#{gclass::PARENT2SEX[parent]}_procreation_age").years)..(birth - gclass.send("min_#{gclass::PARENT2SEX[parent]}_procreation_age").years) elsif life_range (life_range.begin - gclass.send("max_#{gclass::PARENT2SEX[parent]}_procreation_age").years)..(life_range.end - gclass.send("min_#{gclass::PARENT2SEX[parent]}_procreation_age").years) end end end |
.generate_method_parent_fertility_range(parent) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/genealogy/util_methods.rb', line 94 def self.generate_method_parent_fertility_range(parent) define_method "#{parent}_fertility_range" do if parent_birth_range = send("#{parent}_birth_range") (parent_birth_range.begin + gclass.send("min_#{gclass::PARENT2SEX[parent]}_procreation_age").years)..(parent_birth_range.end + gclass.send("max_#{gclass::PARENT2SEX[parent]}_procreation_age").years) end end end |
Instance Method Details
#birth ⇒ Date
Genealogy thinks time in term of Date, not DateTime
8 9 10 |
# File 'lib/genealogy/util_methods.rb', line 8 def birth birth_date.try(:to_date) end |
#birth_range ⇒ Range
optimistic (longest) estimation of birth date. Calculation is based on available dates and max life expectancy
34 35 36 37 38 39 40 |
# File 'lib/genealogy/util_methods.rb', line 34 def birth_range if birth birth..birth # exact elsif death (death - max_le)..death # estimation based on death end end |
#can_procreate_during?(period) ⇒ Boolean
It tests whether fertility range overlaps specified period
70 71 72 |
# File 'lib/genealogy/util_methods.rb', line 70 def can_procreate_during?(period) fertility_range.overlaps? period if (period and fertility_range) end |
#can_procreate_on?(date) ⇒ Boolean
It tests whether fertility range covers specified date
63 64 65 |
# File 'lib/genealogy/util_methods.rb', line 63 def can_procreate_on?(date) fertility_range.cover? date if (date and fertility_range) end |
#death ⇒ Date
Genealogy thinks time in term of Date, not DateTime
14 15 16 |
# File 'lib/genealogy/util_methods.rb', line 14 def death death_date.try(:to_date) end |
#father_birth_range ⇒ Range
optimistic (longest) estimation of father's birth date. Calculation is based on receiver's birth or #life_range, max life expectancy and min and max fertility procreation ages
87 |
# File 'lib/genealogy/util_methods.rb', line 87 generate_method_parent_birth_range(:father) |
#father_fertility_range ⇒ Range
optimistic (longest) estimation of father's fertility range. Calculation is based on receiver's #father_birth_range, min and max fertility procreation ages
101 |
# File 'lib/genealogy/util_methods.rb', line 101 generate_method_parent_fertility_range(:father) |
#fertility_range ⇒ Range
optimistic (longest) estimation of fertility period. Calculation is based on available dates, max life expectancy and min and max fertility procreation ages
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/genealogy/util_methods.rb', line 44 def fertility_range if birth if death if death > birth + min_fpa (birth + min_fpa)..([(birth + max_fpa), death].min) # best estimation else false # died before reaching min fertility age end else (birth + min_fpa)..(birth + max_fpa) # estimation based on birth end elsif death (death - max_le + min_fpa)..death # estimation based on death end end |
#is_female? ⇒ Boolean
124 125 126 127 |
# File 'lib/genealogy/util_methods.rb', line 124 def is_female? return female? if respond_to?(:female?) sex_before_type_cast == gclass.sex_female_value end |
#is_male? ⇒ Boolean
130 131 132 133 |
# File 'lib/genealogy/util_methods.rb', line 130 def is_male? return male? if respond_to?(:male?) sex_before_type_cast == gclass.sex_male_value end |
#life_range ⇒ Range
optimistic (longest) estimation of life period. Calculation is based on available dates and max life expectancy
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/genealogy/util_methods.rb', line 20 def life_range if birth if death birth..death # exact else birth..(birth + max_le) # estimation based on birth end elsif death (death - max_le)..death # estimation based on death end end |
#max_fpa ⇒ Integer
max fertility procreation age in terms of years. It depends on sex
143 144 145 |
# File 'lib/genealogy/util_methods.rb', line 143 def max_fpa gclass.send("max_#{ssex}_procreation_age").years end |
#max_le ⇒ Integer
max life expectancy in terms of years. It depends on sex
137 138 139 |
# File 'lib/genealogy/util_methods.rb', line 137 def max_le gclass.send("max_#{ssex}_life_expectancy").years end |
#min_fpa ⇒ Integer
min fertility procreation age in terms of years. It depends on sex
149 150 151 |
# File 'lib/genealogy/util_methods.rb', line 149 def min_fpa gclass.send("min_#{ssex}_procreation_age").years end |
#mother_birth_range ⇒ Range
optimistic (longest) estimation of mother's birth date. Calculation is based on receiver's birth or #life_range, max life expectancy and min and max fertility procreation ages
88 |
# File 'lib/genealogy/util_methods.rb', line 88 generate_method_parent_birth_range(:mother) |
#mother_fertility_range ⇒ Range
optimistic (longest) estimation of mother's fertility range. Calculation is based on receiver's #mother_birth_range, min and max fertility procreation ages
102 |
# File 'lib/genealogy/util_methods.rb', line 102 generate_method_parent_fertility_range(:mother) |
#opposite_ssex ⇒ Symbol
opposite sex in terms of :male or :female
119 120 121 |
# File 'lib/genealogy/util_methods.rb', line 119 def opposite_ssex gclass::OPPOSITESEX[ssex] end |
#ssex ⇒ Symbol
sex in terms of :male or :female
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/genealogy/util_methods.rb', line 106 def ssex case sex_before_type_cast when gclass.sex_male_value :male when gclass.sex_female_value :female else raise SexError, "Sex value not valid for #{self}" end end |