--Apple-Mail-1--75590609
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charsetO-8859-1;
	format­´wed

Begin forwarded message:

> From: Rub˝¤ Mart¨¤ez <rubmar / gmail.com>
> Date: October 19, 2007 3:46:44 PM CDT
> To: <submission / rubyquiz.com>
> Subject: Please Forward: Ruby Quiz Submission
>
>
> First timer in Ruby Quiz..
>
> Thanks!
>
> Rub˝¤ Mart¨¤ez
>

--Apple-Mail-1--75590609
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode66;
	nameme_window.rb
Content-Disposition: attachment;
	filenameme_window.rb

class TimeWindow
  DAYNAMES  w(Sun Mon Tue Wed Thu Fri Sat)
  
  def initialize(time_window)
    @intervals_in_days  ]
    time_window.split(";").each do |interval|
      @intervals_in_days + imeWindow.parse_interval(interval)
    end
  end
  
  def include?(time)
    @intervals_in_days.empty? or @intervals_in_days.any? { |i| i.include?(time)}
  end
  
  private
  
  def TimeWindow.parse_interval(interval)
    alldays  ]
    alltimeintervals  ]
    
    interval.split(" ").each do |token|
      case token
      when /^\D{3}$/
        alldays + DAYNAMES.index(token)]
      when /^\D{3}-\D{3}$/
        days  oken.split("-")
        alldays + imeWindow.days_in_interval(days[0], days[1])
      when /^\d{4}-\d{4}$/
        timeintervals  oken.split("-")
        alltimeintervals + [timeintervals[0], timeintervals[1]]]
      end
    end
    
    alldays  0..6).to_a if alldays.empty?
    alltimeintervals  ["0000", "2400"]] if alltimeintervals.empty?
    
    interval_in_days  ]
    alldays.each do |day|
      alltimeintervals.each do |timeinterval|
        interval_in_days << IntervalInDay.new(day, timeinterval[0], timeinterval[1])
      end
    end
    
    return interval_in_days
  end
  
  def TimeWindow.days_in_interval(beginday, endday)
    index_begin  AYNAMES.index(beginday)
    index_end  AYNAMES.index(endday)
    if index_begin < ndex_end
      return (index_begin..index_end).to_a
    else
      return (index_begin..6).to_a + (0..index_end).to_a
    end
  end
end

class IntervalInDay
  def initialize(weekday, starttime, endtime)
    @weekday, @starttime, @endtime  eekday, starttime.to_i, (endtime.to_i - 1)
  end
  
  def include?(time)  
     time.wday @weekday &&
     time.strftime("%H%M").to_i.between?(@starttime, @endtime)
  end
end

--Apple-Mail-1--75590609
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset-ASCII;
	formatwed



--Apple-Mail-1--75590609--