Class: Midnight::CronExpression

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

Overview

          • command to execute

┬ ┬ ┬ ┬ ┬ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0) │ │ │ └────────── month (1 - 12) │ │ └─────────────── day of month (1 - 31) │ └──────────────────── hour (0 - 23) └───────────────────────── min (0 - 59)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#day_of_monthObject

:nodoc:



11
12
13
# File 'lib/midnight/cron_expression.rb', line 11

def day_of_month
  @day_of_month
end

#day_of_weekObject

:nodoc:



11
12
13
# File 'lib/midnight/cron_expression.rb', line 11

def day_of_week
  @day_of_week
end

#force_run_every_minuteObject

:nodoc:



11
12
13
# File 'lib/midnight/cron_expression.rb', line 11

def force_run_every_minute
  @force_run_every_minute
end

#hourObject

:nodoc:



11
12
13
# File 'lib/midnight/cron_expression.rb', line 11

def hour
  @hour
end

#minuteObject

:nodoc:



11
12
13
# File 'lib/midnight/cron_expression.rb', line 11

def minute
  @minute
end

#monthObject

:nodoc:



11
12
13
# File 'lib/midnight/cron_expression.rb', line 11

def month
  @month
end

Instance Method Details

#to_sObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/midnight/cron_expression.rb', line 13

def to_s
  return '* * * * *' if (@force_run_every_minute === true)

  expression_parts = [
    get_attribute(:minute),
    get_attribute(:hour),
    get_attribute(:day_of_month),
    get_attribute(:month),
    get_attribute(:day_of_week)
  ]

  # Better to return nil than accidentally recommend that people run a job every minute
  # Set force_run_every_minute to true to return * * * * * 
  if (expression_parts.select { |x| x != '*'}.empty?)
    return nil
  end 

  expression_parts.join(' ')
end