Created
January 24, 2012 23:43
-
-
Save akahn/1673543 to your computer and use it in GitHub Desktop.
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
| class AdvancingTimeRange | |
| def initialize(time = '2009-03-01') | |
| @cursor = DateTime.parse(time) | |
| end | |
| def next(increment_by) | |
| range = @cursor..@cursor + increment_by | |
| @cursor = range.end | |
| range | |
| end | |
| end |
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
| class AscendingRange | |
| delegate :begin, :end, :to => @range | |
| def initialize(begin = 1, end = 50_000) | |
| @range = begin..end | |
| end | |
| def advance(by = 50_000) | |
| @range = (@range.begin + by)..(@range.end + by) | |
| end | |
| end |
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
| class MonthSpan | |
| def initialize(time = '2009-03-01') | |
| @start = DateTime.parse(time) | |
| end | |
| def range | |
| @start..@start + 1.month | |
| end | |
| def next | |
| @start = @start + 1.month | |
| range | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment