Skip to content

Instantly share code, notes, and snippets.

@macprince
Created August 10, 2017 04:30
Show Gist options
  • Save macprince/afd0499ace98c0cce48a94514b877bfc to your computer and use it in GitHub Desktop.
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.
#!/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