From cceb3b63bd8f1ee160e3022978df2ded13a44aa1 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 3 Jan 2010 23:43:58 -0500 Subject: [PATCH] start work on scheduler --- .gitignore | 2 ++ classes/Scheduler.rb | 32 ++++++++++++++++++++++++++++++++ tests/TestScheduler.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 classes/Scheduler.rb create mode 100644 tests/TestScheduler.rb 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