From: Ruby Quiz Date: 2006-11-11T00:01:15+09:00 Subject: [QUIZ] VCR Program Manager (#101) The three rules of Ruby Quiz: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have passed from the time on this message. 2. Support Ruby Quiz by submitting ideas as often as you can: http://www.rubyquiz.com/ 3. Enjoy! Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone on Ruby Talk follow the discussion. Please reply to the original quiz message, if you can. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= by Franå·½ois Beausoleil The goal of this Ruby Quiz is to make a Video Cassette Recorder program manager. The user is responsible for saying what times to record, and then the VCR will query the program manager regularly to determine if it should be recording, and 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, if the 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, and record 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 recording. Interesting, optional features: fuzzy time (start a bit before and end a bit after the specific times, to catch shows starting early / ending late) and 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 should # 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: http://www.rubyquiz.com/program_manager_test.rb