Skip to content

Instantly share code, notes, and snippets.

@sixtyfive
Created July 17, 2011 18:28
Show Gist options
  • Save sixtyfive/1087900 to your computer and use it in GitHub Desktop.
Save sixtyfive/1087900 to your computer and use it in GitHub Desktop.
Ugly method for making a nested hash
def build_results_array(start_date, end_date, user)
res = {}
years = Year.date_range_scoped_by_user(start_date, end_date, user)
res[:years] = {}
for year in years do
puts "*** adding year"
res[:years][year.name] = {:id => year.id}
months = Month.date_range_scoped_by_user_and_year(start_date, end_date, user, year)
res[:years][year.name][:months] = {}
for month in months do
puts "*** adding month"
res[:years][year.name][:months][month.name] = {:id => month.id}
weeks = Week.date_range_scoped_by_user_and_month(start_date, end_date, user, month)
res[:years][year.name][:months][month.name][:weeks] = {}
for week in weeks do
puts "*** adding week"
res[:years][year.name][:months][month.name][:weeks][week.name] = {:id => week.id}
days = Day.date_range_scoped_by_user_and_week_and_month(start_date, end_date, user, week, month)
res[:years][year.name][:months][month.name][:weeks][week.name][:days] = {}
for day in days do
puts "*** adding day"
res[:years][year.name][:months][month.name][:weeks][week.name][:days][day.name] = {:id => day.id}
res[:years][year.name][:months][month.name][:weeks][week.name][:days][day.name] = {:activities => day.activities} if day.activities.any?
end
end
end
end
return res
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment