Created
February 20, 2011 08:54
-
-
Save ltw/835835 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
[:last, :this, :next].each do |week| | |
define_method("#{week}_week") { schedule(week) } | |
end | |
def schedule(week) | |
@schedule ||= YAML.load_file('schedule.yml')["schedule"] | |
@schedule.select {|d| date_range(week.to_sym).include?(d)} | |
end | |
def date_range(week) | |
today = Date.today | |
# if it's the weekend, look at next week | |
today = (today.saturday? || today.sunday?) ? today.next_week : today.monday | |
start_date = case week | |
when :this then today.monday | |
when :next then today.next_week | |
when :last then today.monday - 7 | |
end | |
(start_date..(start_date+6)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment