Created
January 12, 2015 16:01
-
-
Save datt/55633b0fad5e81d57405 to your computer and use it in GitHub Desktop.
fake year range string
This file contains hidden or 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
| # Usage YearRange.new(2).range_string | |
| # "1990-1991 | 2011-2013" | |
| class YearRange | |
| def initialize(range = 1) | |
| @range = range | |
| @years = (1980..2015).to_a | |
| end | |
| def collect | |
| divide_factor = @years.size/@range | |
| @year_ranges = @years.each_slice(divide_factor).to_a.map do |years| | |
| years.sample(2).sort | |
| end | |
| end | |
| def range_string | |
| @year_ranges.map{|a| a.join('-')}.join(' | ') | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment