school_year 0.2.0
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 +7 -0
- data/lib/school_year.rb +53 -0
- metadata +57 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fbe56e5041f75f9252c4fd8a5741618213ba65ab03bb34eda204ba093f27416a
|
|
4
|
+
data.tar.gz: 45250bf23366d3be3f6f4adbc0e60937a732a297a80a82bb8968f15edb899660
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: be0817cb9558ba5280f61743f81fd83d471bcc2d42fcd15d01dfed2bfd0d293f8674c672860a55b405a2469e8e01b6acde49c022a76bc1e88f8c375c038ee339
|
|
7
|
+
data.tar.gz: b907542a1b22368aecded760581ba3ea68faec635d85d2b14117c971f112ad6ea3154cce7463a57a45c573277c5e4e16907adc21e8697bfff57850d6d848bcce
|
data/lib/school_year.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
class SchoolYear
|
|
4
|
+
class << self
|
|
5
|
+
|
|
6
|
+
def grade_to_graduation_year(grade, academic_year=academic_year(Date.today))
|
|
7
|
+
return nil unless (0..12).include? grade
|
|
8
|
+
academic_year + (12 - grade)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def grade_to_year(grade, standard_graduation_year)
|
|
12
|
+
standard_graduation_year - 12 + grade
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def year_to_grade(year, standard_graduation_year)
|
|
16
|
+
year + 12 - standard_graduation_year
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def academic_year(date)
|
|
20
|
+
date.year + (date.month < 7 ? 0 : 1)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def grade_on_date(date, standard_graduation_year)
|
|
24
|
+
year_to_grade(academic_year(date), standard_graduation_year)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def default_first_day_of_school(academic_year_or_date)
|
|
28
|
+
if academic_year_or_date.class == Integer
|
|
29
|
+
Date.new(academic_year_or_date - 1, 9, 1)
|
|
30
|
+
elsif academic_year_or_date.class == Date
|
|
31
|
+
Date.new(academic_year_or_date.year - (academic_year_or_date.month < 7 ? 1 : 0), 9, 1)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def default_last_day_of_school(academic_year_or_date)
|
|
36
|
+
if academic_year_or_date.class == Integer
|
|
37
|
+
Date.new(academic_year_or_date, 6, 15)
|
|
38
|
+
elsif academic_year_or_date.class == Date
|
|
39
|
+
Date.new(academic_year_or_date.year + (academic_year_or_date.month < 7 ? 0 : 1), 6, 15)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def school_days_elapsed(date = nil, first_attendance_day = nil)
|
|
44
|
+
if date
|
|
45
|
+
first_attendance_day ||= default_first_day_of_school(date)
|
|
46
|
+
(date - first_attendance_day) * 5 / 7.0
|
|
47
|
+
else
|
|
48
|
+
(default_last_day_of_school(1901) - default_first_day_of_school(1901)) * 5 / 7.0 # 1901 in order to miss leap year
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: school_year
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Peter Kirwin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-09-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: "\n # School Year\n Simple logic for translating between academic
|
|
14
|
+
year and grade for a student\n\n ## Sample Usage\n `SchoolYear.grade_to_graduation_year(grade,
|
|
15
|
+
academic_year)` determines the graduation year for a student based on their grade
|
|
16
|
+
and the academic year `SchoolYear.grade_to_year(grade, graduation_year)` determines
|
|
17
|
+
the calendar year from the student's grade based on the graduation year\n `SchoolYear.year_to_grade(year,
|
|
18
|
+
graduation_year)` determines the student's grade from the calendar year based on
|
|
19
|
+
the graduation year\n `SchoolYear.default_first_day_of_school(academic_year_or_date)`
|
|
20
|
+
determines the first day of school (as September 1st) based on an integer representing
|
|
21
|
+
the academic year (e.g., 1998), or a date (e.g., '1998-04-04'.to_date)\n `SchoolYear.default_last_day_of_school(academic_year_or_date)`
|
|
22
|
+
determines the last day of school (as June 15th) based on an integer representing
|
|
23
|
+
the academic year (e.g., 1998), or a date (e.g., '1998-04-04'.to_date)\n `SchoolYear.school_days_elapsed(date,
|
|
24
|
+
first_attendace_day)` determines the approximate number of days elapsed from the
|
|
25
|
+
first_attendance_day to the date. Both arguments can be blank: if date is blank,
|
|
26
|
+
the approximate number of total days in the 1901 school year will be returned.\n
|
|
27
|
+
\ "
|
|
28
|
+
email: peter@puzzlesandwich.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- lib/school_year.rb
|
|
34
|
+
homepage: http://www.puzzlesandwich.com
|
|
35
|
+
licenses:
|
|
36
|
+
- MIT
|
|
37
|
+
metadata: {}
|
|
38
|
+
post_install_message:
|
|
39
|
+
rdoc_options: []
|
|
40
|
+
require_paths:
|
|
41
|
+
- lib
|
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0'
|
|
52
|
+
requirements: []
|
|
53
|
+
rubygems_version: 3.2.4
|
|
54
|
+
signing_key:
|
|
55
|
+
specification_version: 4
|
|
56
|
+
summary: School Year Logic
|
|
57
|
+
test_files: []
|