Class: SchoolYear
- Inherits:
-
Object
- Object
- SchoolYear
- Defined in:
- lib/school_year.rb
Class Method Summary collapse
- .academic_year(date) ⇒ Object
- .default_first_day_of_school(academic_year_or_date) ⇒ Object
- .default_last_day_of_school(academic_year_or_date) ⇒ Object
- .grade_on_date(date, standard_graduation_year) ⇒ Object
- .grade_to_graduation_year(grade, academic_year = academic_year(Date.today)) ⇒ Object
- .grade_to_year(grade, standard_graduation_year) ⇒ Object
- .school_days_elapsed(date = nil, first_attendance_day = nil) ⇒ Object
- .year_to_grade(year, standard_graduation_year) ⇒ Object
Class Method Details
.academic_year(date) ⇒ Object
19 20 21 |
# File 'lib/school_year.rb', line 19 def academic_year(date) date.year + (date.month < 7 ? 0 : 1) end |
.default_first_day_of_school(academic_year_or_date) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/school_year.rb', line 27 def default_first_day_of_school(academic_year_or_date) if academic_year_or_date.class == Integer Date.new(academic_year_or_date - 1, 9, 1) elsif academic_year_or_date.class == Date Date.new(academic_year_or_date.year - (academic_year_or_date.month < 7 ? 1 : 0), 9, 1) end end |
.default_last_day_of_school(academic_year_or_date) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/school_year.rb', line 35 def default_last_day_of_school(academic_year_or_date) if academic_year_or_date.class == Integer Date.new(academic_year_or_date, 6, 15) elsif academic_year_or_date.class == Date Date.new(academic_year_or_date.year + (academic_year_or_date.month < 7 ? 0 : 1), 6, 15) end end |
.grade_on_date(date, standard_graduation_year) ⇒ Object
23 24 25 |
# File 'lib/school_year.rb', line 23 def grade_on_date(date, standard_graduation_year) year_to_grade(academic_year(date), standard_graduation_year) end |
.grade_to_graduation_year(grade, academic_year = academic_year(Date.today)) ⇒ Object
6 7 8 9 |
# File 'lib/school_year.rb', line 6 def grade_to_graduation_year(grade, academic_year=academic_year(Date.today)) return nil unless (0..12).include? grade academic_year + (12 - grade) end |
.grade_to_year(grade, standard_graduation_year) ⇒ Object
11 12 13 |
# File 'lib/school_year.rb', line 11 def grade_to_year(grade, standard_graduation_year) standard_graduation_year - 12 + grade end |
.school_days_elapsed(date = nil, first_attendance_day = nil) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/school_year.rb', line 43 def school_days_elapsed(date = nil, first_attendance_day = nil) if date first_attendance_day ||= default_first_day_of_school(date) (date - first_attendance_day) * 5 / 7.0 else (default_last_day_of_school(1901) - default_first_day_of_school(1901)) * 5 / 7.0 # 1901 in order to miss leap year end end |
.year_to_grade(year, standard_graduation_year) ⇒ Object
15 16 17 |
# File 'lib/school_year.rb', line 15 def year_to_grade(year, standard_graduation_year) year + 12 - standard_graduation_year end |