The three rules of Ruby Q.:
Please do not post any solutions or spoiler discussion for this quiz
48 hours have passed from the time on this message.
Support Ruby Q. by submitting ideas as often as you can:
Suggestion: A [QUIZ] in the subject of emails about the problem helps
on Ruby T. follow the discussion. Please reply to the original quiz
if you can.
by FranÃ§ois Beausoleil
The goal of this Ruby Q. is to make a Video Cassette Recorder program
The user is responsible for saying what times to record, and then the
query the program manager regularly to determine if it should be
if so, on which channel.
The interesting bit in this quiz is the conflict resolution.
Normally, users specify recording schedules such as this:
Monday to Friday, 3 PM to 4 PM, channel 8
Specific programs might overlap. Assuming the above program is active,
user added this program:
Wednesday Nov 8, 3:30 PM to 5 PM, channel 12
We should record from 3 to 3:30 channel 8, then switch to channel 12,
until 5 PM.
Another variation might be:
Thursday Nov 9, 3:30 PM to 4:30 PM, channel 8
In this case, the channel didn’t change, so we should just keep on
Interesting, optional features: fuzzy time (start a bit before and end a
after the specific times, to catch shows starting early / ending late)
taking care of DST.
Your program manager must implement the following interface:
# Query to determine if we should be recording at any particular # moment. It can be assumed that the VCR will query the program # manager at most twice per minute, and with always increasing minutes. # New programs may be added between two calls to #record?. # # This method must return either a +nil+, indicating to stop recording, # or don't start, or an +Integer+, which is the channel number we
# be recording.
def record?(time); end
# Adds a new Program to the list of programs to record. def add(program_details); end
Your task is to provide an implementation for the ProgramManager.
You can see the unit tests I used at: