Created
September 25, 2012 23:31
-
-
Save mlevans/3785085 to your computer and use it in GitHub Desktop.
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
class GradeLevel | |
attr_accessor :number | |
def initialize(num) | |
@number = num | |
end | |
def order_index | |
number =~ /K(\d)/ ? $1.to_i : (number.to_i + 2) | |
end | |
end | |
def short_string(collection) | |
# as_i = collection.all.map{|x| x.order_index}.sort | |
as_i = collection.map(&:order_index).sort | |
collection.sort_by(&:order_index).slice_before {|x| !as_i.include?(x.order_index-1)}.map {|arr| "#{arr.first.number}-#{arr.last.number}"}*", " | |
end | |
grades = ["K0", "K1", "K2", "4", "5", "6", ].map {|num| GradeLevel.new(num)} | |
short_string(grades) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
will also work