switch to strings

This commit is contained in:
John Bintz 2010-01-04 19:44:39 -05:00
parent b0de0b1d98
commit e99e08f3e7
2 changed files with 14 additions and 14 deletions

View File

@ -22,7 +22,7 @@ class Scheduler
def ok_to_add(date, breaks) def ok_to_add(date, breaks)
ok = true ok = true
breaks.each do |i| breaks.each do |i|
if (i[:from] <= date) && (i[:to] >= date) if (i['from'] <= date) && (i['to'] >= date)
ok = false ok = false
end end
end end
@ -32,13 +32,13 @@ class Scheduler
def schedule(parameters, to_produce) def schedule(parameters, to_produce)
dates = [] dates = []
if parameters[:start] if parameters['start']
current = parameters[:start] current = parameters['start']
breaks = parameters[:breaks] || [] breaks = parameters['breaks'] || []
while dates.length < to_produce while dates.length < to_produce
interval = parameters[:interval].shift interval = parameters['interval'].shift
case interval.class.to_s case interval.class.to_s
when 'String' when 'String'
@ -57,7 +57,7 @@ class Scheduler
current += interval current += interval
end end
parameters[:interval] << interval parameters['interval'] << interval
end end
end end

View File

@ -13,26 +13,26 @@ class TestScheduler < Test::Unit::TestCase
[ [
[ [
{ {
:start => DateTime.parse('2010-01-01'), 'start' => DateTime.parse('2010-01-01'),
:interval => Scheduler::WEEKLY 'interval' => Scheduler::WEEKLY
}, },
2, 2,
[ DateTime.parse('2010-01-01'), DateTime.parse('2010-01-08') ] [ DateTime.parse('2010-01-01'), DateTime.parse('2010-01-08') ]
], ],
[ [
{ {
:start => DateTime.parse('2010-01-01'), 'start' => DateTime.parse('2010-01-01'),
:interval => [ 'monday' ] 'interval' => [ 'monday' ]
}, },
2, 2,
[ DateTime.parse('2010-01-04'), DateTime.parse('2010-01-11') ] [ DateTime.parse('2010-01-04'), DateTime.parse('2010-01-11') ]
], ],
[ [
{ {
:start => DateTime.parse('2010-01-01'), 'start' => DateTime.parse('2010-01-01'),
:interval => Scheduler::DAILY, 'interval' => Scheduler::DAILY,
:breaks => [ 'breaks' => [
{ :from => DateTime.parse('2010-01-03'), :to => DateTime.parse('2010-01-05') } { 'from' => DateTime.parse('2010-01-03'), 'to' => DateTime.parse('2010-01-05') }
] ]
}, },
4, 4,