Class: Cronos::Interval::RepeatInterval

Inherits:
Object
  • Object
show all
Defined in:
lib/cronos.rb

Instance Method Summary collapse

Constructor Details

#initialize(multiple, interval) ⇒ RepeatInterval

Returns a new instance of RepeatInterval.



306
307
308
# File 'lib/cronos.rb', line 306

def initialize(multiple, interval)
  @multiple, @interval = multiple, interval
end

Instance Method Details

#calculate_intervals(base, initial = 0) ⇒ Object



335
336
337
338
339
340
# File 'lib/cronos.rb', line 335

def calculate_intervals(base, initial = 0)
  repeats = (base / @multiple) - 1
  set = [initial]
  1.upto(repeats) {|factor| set << (factor * @multiple + initial) }
  @intervals = set
end

#hoursObject



317
318
319
320
321
322
323
# File 'lib/cronos.rb', line 317

def hours
  raise 'Multiple of hours will not fit into a day' if (24 % @multiple) > 0
  calculate_intervals(24)
  @interval.min  = 0
  @interval.hour = self 
  @interval
end

#minutesObject



310
311
312
313
314
315
# File 'lib/cronos.rb', line 310

def minutes
  raise 'Multiple of minutes will not fit into an hour' if (60 % @multiple) > 0
  calculate_intervals(60)
  @interval.min = self 
  @interval
end

#monthsObject



325
326
327
328
329
330
331
332
333
# File 'lib/cronos.rb', line 325

def months
  raise 'Multiple of months will not fit into a year' if (12 % @multiple) > 0
  calculate_intervals(12, 1)
  @interval.min  ||= 0
  @interval.hour ||= 0
  @interval.day  ||= 1
  @interval.month = self 
  @interval
end

#to_aObject



346
347
348
# File 'lib/cronos.rb', line 346

def to_a
  @intervals
end

#to_sObject



342
343
344
# File 'lib/cronos.rb', line 342

def to_s
  @intervals.join(',')
end