diff --git a/.gitignore b/.gitignore index 5236e1e..da43a1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *~ +.loadpath +.project diff --git a/classes/Scheduler.rb b/classes/Scheduler.rb new file mode 100644 index 0000000..0608ec0 --- /dev/null +++ b/classes/Scheduler.rb @@ -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 diff --git a/tests/TestScheduler.rb b/tests/TestScheduler.rb new file mode 100644 index 0000000..72e6a34 --- /dev/null +++ b/tests/TestScheduler.rb @@ -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