This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# frozen_string_literal: true
classAcademicYear<ActiveRecord::Base
defself.find_by_date(date)
year=parse_year_range(date:)
range="#{year.start}-#{year.end.to_s[2,3]}"
academic_years[range]
end
defformatted_range
years=range.split('-')
"#{years.first}– 20#{years.second}"
end
private
defself.parse_year_range(date:)
year=date.year
ifdate.month>6
AcademicYearRange.new(year,year+1)
else
AcademicYearRange.new(year-1,year)
end
end
# This may cause problems if academic years get loaded from csv instead of the current method that requires a code change to the seeder script. This is because a change in code will trigger a complete reload of the application whereas loading from csv does not. This means if we change academic year to load from csv, the set of academic years will be stale when new years are added.