Skip to content

Instantly share code, notes, and snippets.

@moskyb
Created January 27, 2016 23:13
Show Gist options
  • Save moskyb/721e6718a2dd35c48433 to your computer and use it in GitHub Desktop.
Save moskyb/721e6718a2dd35c48433 to your computer and use it in GitHub Desktop.
if @member.years[0]
year_numbers = @member.years.map { |year|
year.description.to_i
}.sort
first_year = year_numbers.shift
year_numbers.reduce([[first_year]]) do |year_collection, year|
if year_collection[-1][1] == year-1 || !year_collection[-1][1]
(year_collection[-1][1] = year; year_collection)
else
(year_collection)+[[year]]
end
end.map { |collection| collection.join(' - ') }.join('; ')
else
'None'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment