start work on scheduler

This commit is contained in:
John Bintz 2010-01-03 23:43:58 -05:00
parent f5fa6f7373
commit cceb3b63bd
3 changed files with 69 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
*~
.loadpath
.project

32
classes/Scheduler.rb Normal file
View File

@ -0,0 +1,32 @@
require 'singleton'
class Scheduler
include Singleton
WEEKLY = [ 7 ]
def schedule(parameters, to_produce)
dates = []
if parameters[:start]
current = parameters[:start]
1.upto(to_produce) do |i|
interval = parameters[:interval].shift
case interval.class.to_s
when 'Symbol'
when 'Fixnum'
end
dates << current
current += interval
parameters[:interval] << interval
end
end
dates
end
end

35
tests/TestScheduler.rb Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/ruby
require 'rubygems'
require 'test/unit'
require File.dirname(__FILE__) + '/../classes/Scheduler.rb'
class TestScheduler < Test::Unit::TestCase
def setup
@scheduler = Scheduler.instance
end
def test_schedule
[
[
{
:start => DateTime.parse('2010-01-01'),
:interval => Scheduler::WEEKLY
},
2,
[ DateTime.parse('2010-01-01'), DateTime.parse('2010-01-08') ]
],
[
{
:start => DateTime.parse('2010-01-01'),
:interval => [ :mondays ]
},
2,
[ DateTime.parse('2010-01-04'), DateTime.parse('2010-01-11') ]
],
].each do |parameters, to_produce, expected_results|
assert_equal expected_results, @scheduler.schedule(parameters, to_produce)
end
end
end