lib/crontab_expression.rb
def times_for(granularity)
    expr = expression[granularity]
    return nil unless expr
    return nil if expr == ""
    return nil if expr.split(",").include? "*"

    [].tap do |times|
      expr.split(",").each do |value|
        time, divisor = value.split "/"
        divisor = divisor.to_i if divisor
        start_time, end_time = time.split "-"
        if time == "*" # will always have a divisor
          divided = RANGES[granularity].select do |g|
            g % divisor == 0
          end
          times.concat divided
        else
          if end_time
            d = divisor || 1
            start_time.to_i.upto(end_time.to_i) { |t| times << t if t % d == 0 }
          else
            times << start_time.to_i
          end
        end
      end
    end
  end
# Calculate the values for the given cron expression
#
# granularity - what granularity this expression applies to, e.g. :minute,
#               :hour, :day, :month, :day_of_week
#
# Returns an array of integer times, or nil if no expressions apply.
Calculate the values for the given cron expression
granularity - what granularity this expression applies to, e.g.

Returns an array of integer times, or nil if no expressions apply.
Calculate the values for the given cron expression granularity - what granularity this expression applies to e . g . Returns an array of integer times or nil if no expressions apply .
def times_for(granularity)
    expr = expression[granularity]
    return nil unless expr
    return nil if expr == ""
    return nil if expr.split(",").include? "*"
    [].tap do |times|
      expr.split(",").each do |value|
        time, divisor = value.split "/"
        divisor = divisor.to_i if divisor
        start_time, end_time = time.split "-"
        if time == "*" 
          divided = RANGES[granularity].select do |g|
            g % divisor == 0
          end
          times.concat divided
        else
          if end_time
            d = divisor || 1
            start_time.to_i.upto(end_time.to_i) { |t| times << t if t % d == 0 }
          else
            times << start_time.to_i
          end
        end
      end
    end
  end
def times_for ( granularity ) expr = expression [ granularity ] return nil unless expr return nil if expr == "" return nil if expr . split ( "," ) . include? "*" [ ] . tap do | times | expr . split ( "," ) . each do | value | time , divisor = value . split "/" divisor = divisor . to_i if divisor start_time , end_time = time . split "-" if time == "*" divided = RANGES [ granularity ] . select do | g | g % divisor == 0 end times . concat divided else if end_time d = divisor || 1 start_time . to_i . upto ( end_time . to_i ) { | t | times << t if t % d == 0 } else times << start_time . to_i end end end end end
Calculate the values for the given cron expression
granularity - what granularity this expression applies to, e.g.
Calculate the values for the given cron expression granularity - what granularity this expression applies to e . g .
# will always have a divisor
granularity