Sha256: 7d2f88e9d0a702c27ee42a76a1f74612b4d6fae84c4b6e25e673d97f95642619

Contents?: true

Size: 951 Bytes

Versions: 15

Compression:

Stored size: 951 Bytes

Contents

module Hookit
  module Helper
    module Cron
      
      MINUTES = 59
      HOURS   = 23
      DAYS    = 31
      MONTHS  = 12
      WEEKDAY = 7
      
      def sanitize_cron(cron)
      
        time = cron.split(' ')
        
        time[0] = compatible_cron(time[0],MINUTES)
        time[1] = compatible_cron(time[1],HOURS)
        time[2] = compatible_cron(time[2],DAYS, 1)
        time[3] = compatible_cron(time[3],MONTHS, 1)
        time[4] = compatible_cron(time[4],WEEKDAY)
      
        time.join(' ')
      end
      
      protected

      # converts */x cron format into solaris compatible format
      def compatible_cron(time, limit, start = 0)
        if time =~ /\//
          increment = time.split('/')[1].to_i
          x, y      = start, []
          for i in 0..limit/increment
            y[i] = x
            x    +=increment
          end
          time = y.join(',')
        end
        time
      end

    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
micro-hookit-0.12.13 lib/hookit/helper/cron.rb
micro-hookit-0.12.12 lib/hookit/helper/cron.rb
micro-hookit-0.12.11 lib/hookit/helper/cron.rb
hookit-0.12.3 lib/hookit/helper/cron.rb
hookit-0.12.2 lib/hookit/helper/cron.rb
hookit-0.12.1 lib/hookit/helper/cron.rb
hookit-0.12.0 lib/hookit/helper/cron.rb
hookit-0.11.2 lib/hookit/helper/cron.rb
hookit-0.11.1 lib/hookit/helper/cron.rb
hookit-0.11.0 lib/hookit/helper/cron.rb
hookit-0.10.0 lib/hookit/helper/cron.rb
hookit-0.9.2 lib/hookit/helper/cron.rb
hookit-0.9.0 lib/hookit/helper/cron.rb
hookit-0.8.0 lib/hookit/helper/cron.rb
hookit-0.7.11 lib/hookit/helper/cron.rb