start work on scheduler
This commit is contained in:
parent
f5fa6f7373
commit
cceb3b63bd
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
*~
|
||||
.loadpath
|
||||
.project
|
||||
|
||||
|
32
classes/Scheduler.rb
Normal file
32
classes/Scheduler.rb
Normal 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
35
tests/TestScheduler.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user