@@ -4,7 +4,7 @@ module GogglesDb
4
4
#
5
5
# = GogglesDb::Swimmer
6
6
#
7
- # - version: 7-0.7.10
7
+ # - version: 7-0.8.00
8
8
# - author: Steve A.
9
9
#
10
10
class Swimmer < ApplicationRecord
@@ -65,14 +65,37 @@ class Swimmer < ApplicationRecord
65
65
#-- ------------------------------------------------------------------------
66
66
#++
67
67
68
- # Returns the swimmer age (as a numeric value) for a given +date+.
68
+ # Returns the approximate swimmer age (as a numeric value) for a given +date+.
69
69
#
70
70
# == Params
71
71
# - <tt>date</tt>: the date for which the age must be computed; default: +today+.
72
72
def age ( date = Time . zone . today )
73
73
date . year - year_of_birth
74
74
end
75
75
76
+ # Computes the swimmer's age, possily adjusted for the proper current category age range (5-years x category),
77
+ # according to the given meeting date.
78
+ #
79
+ # == Rationale:
80
+ # Given that Championships usually start in the second half of an year and we only consider the
81
+ # year of birth (as if the swimmer was born on the 1st of January of that year), the swimmer's age
82
+ # must be rounded up by 1 if the session month is in the second half of the current year - implying
83
+ # the first half of its season.
84
+ #
85
+ # === Example:
86
+ # YOB: 2000, current_year: 2024, session_month: 7 => age 24 => category 'M20' (meeting falls inside ending part of season 2023-2024)
87
+ # YOB: 2000, current_year: 2024, session_month: 9 => age 25 => category 'M25' (meeting falls inside starting part of season 2024-2025)
88
+ #
89
+ # == Params:
90
+ # - <tt>meeting_date</tt>: the meeting +Date+ to be considered; default: +today+
91
+ #
92
+ # == Returns:
93
+ # The swimmer's age (as a numeric value) for a given +date+.
94
+ # Raises an error unless +meeting_date+ responds to #year & #month (a valid +Date+).
95
+ def age_for_category_range ( meeting_date = Time . zone . today )
96
+ meeting_date . year - year_of_birth + ( meeting_date . month > 8 ? 1 : 0 )
97
+ end
98
+
76
99
# Returns the array list of all the distinct team IDs associated
77
100
# to the object row through the available Badges.
78
101
# Returns an empty array when nothing is found.
0 commit comments