class CronUnit

Attributes

cron_form[RW]
maximum[RW]
minimum[RW]

Public Class Methods

new(cron, min, max) click to toggle source
# File lib/khronotab/cron_unit.rb, line 4
def initialize(cron, min, max)
  @cron_form = cron
  @minimum = min
  @maximum = max
end

Public Instance Methods

contains?(value) click to toggle source
# File lib/khronotab/cron_unit.rb, line 10
def contains?(value)
  expanded_form.include?(value)
end
expand_interval(segment) click to toggle source
# File lib/khronotab/cron_unit.rb, line 19
def expand_interval(segment)
  counter = 0
  times = []
  interval = segment.split('/').map! { |x|
    if x == '*'
      x = @maximum
    else
      x.to_i
    end
  }
  while counter < interval[0]
    times.push(counter)
    counter += interval[1]
  end
  times
end
expand_range(segment) click to toggle source
# File lib/khronotab/cron_unit.rb, line 14
def expand_range(segment)
  range = segment.split('-').map! { |x| x.to_i }
  (range[0] .. range[1]).to_a
end
expanded_form() click to toggle source
# File lib/khronotab/cron_unit.rb, line 36
def expanded_form
  values = []
  @cron_form.split(',').each do |segment|
    case segment
      when /-/ #range
        values.concat(expand_range(segment))
      when /\// #interval
        values.concat(expand_interval(segment))
      when /[*]/
        values.concat((@minimum .. @maximum).to_a)
      else
        values << segment.to_i
    end
  end
  values.sort.uniq
end
to_s() click to toggle source
# File lib/khronotab/cron_unit.rb, line 53
def to_s
  @cron_form
end