Created
August 10, 2017 04:30
-
-
Save macprince/afd0499ace98c0cce48a94514b877bfc to your computer and use it in GitHub Desktop.
Returns a list of the graduation years for students in a given grade this year.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
%w[date].each{|lib| require lib} | |
class Integer | |
def ordinal | |
cardinal = self.abs | |
digit = cardinal%10 | |
if (1..3).include?(digit) and not (11..13).include?(cardinal%100) | |
self.to_s << %w{st nd rd}[digit-1] | |
else | |
self.to_s << 'th' | |
end | |
end | |
end | |
# Number of grades to compute the graduation years for. | |
# K-12 - 13 | |
# K-8 - 9 | |
grades = 13 | |
this_year = Date.today.year | |
grades.times { |y| | |
grade = grades - y - 1 | |
if (grade == 0) | |
pretty_grade = "Kindergarten" | |
else | |
pretty_grade = "#{grade.ordinal} Grade" | |
end | |
puts "#{pretty_grade} - #{this_year + y + 1}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment