Monday, 12 August 2013

Checking a hash for the existence of a matching value

Checking a hash for the existence of a matching value

I'm building a school calendar that lists classes ("sections") and
displays semester and exam dates for those classes. The calendar is fed a
hash that is defined in the Section.rb model:
def get_calendar
calendar = {}
calendar[:semesters] = Semester.where(section_id: self.id)
calendar[:exams] = Exam.where(section_id: self.id)
{ :calendar => calendar }
end
The Semester and Exam objects have a name, start_date and end_date.
When looping through each day of the calendar, how can I check if there's
a semester or exam with a start_date or end_date for that day of the loop?
If there is a semester or exam with either a start_date or end_date that
matches the calendar date, I would to display the name.
The calendar dates and the start_date and end_date fields all use the Date
class (link).
I sincerely appreciate the help. I can clarify the question if needed :)
Thank you!

No comments:

Post a Comment