# reservation_generator.rb 

# $Id: reservation_generator.rb,v 1.6 2002/05/06 02:22:18 kenji Exp $

# 2002/4/30  Ken-ichi HASHIMOTO <ken@po.ganseki.ne.jp>
# Copyright (C) 2002 Ken-ichi HASHIMOTO <ken@po.ganseki.ne.jp>
# This is free software with ABSOLUTELY NO WARRANTY.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

## This is library
##                      by ken-ichi hashimoto

# Project infomation:
#   manager: hasimoto

class ReservationList<Array
	def loadFrom( aFilename )
		open( aFilename ,'r' ) do |file|
			file.each do |line|
				next if line=~/^\s*$/
				next if line=~/^#/
				self << line.chomp.split(/\s+/)
			end
		end
	end
end

class ReservationGenerator
	def initialize()
		@list = nil			# ReservationList
	end
	def setReservationList( aReservationList )
		@list = aReservationList
	end
	def createBetween( aStartTime , aEndTime )
		ret = Array.new
		if @list.size < 1 then
			return ret 
		end
		@list.each do |dat|
			alg = dat[0]
			require "repeat_mode_plugins/#{alg}.rb"
			alg = eval( "Rmp#{alg}.new" )
			alg.setParameter( dat )
			s = aStartTime.to_i
			e = aEndTime.to_i
			s.step(e,60*60*24) do |time|
				val = alg.format( Time.at(time) )
				if val then
					ret << val
				end
			end
		end
		ret
	end
end
