Skip to content

Instantly share code, notes, and snippets.

@ltw
Created February 20, 2011 08:54
Show Gist options
  • Save ltw/835835 to your computer and use it in GitHub Desktop.
Save ltw/835835 to your computer and use it in GitHub Desktop.
[: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