Class: Cronline::Cron

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cron_expression) ⇒ Cron

Returns a new instance of Cron.



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

def initialize(cron_expression)
  @seconds = CronSeconds.new(cron_expression)
  @minutes = CronMinutes.new(cron_expression)
  @hours = CronHours.new(cron_expression)

  @months = CronMonths.new(cron_expression)
  @years = CronYears.new(cron_expression)

  cron_days_of_month = CronDaysOfMonth.new(cron_expression)
  cron_days_of_week = CronDaysOfWeek.new(cron_expression)
  if (cron_days_of_month).active? && (cron_days_of_week).active?
    fail 'Only one days field is allowed'
  elsif cron_days_of_week.active?
    @days = cron_days_of_week
  elsif cron_days_of_month.active?
    @days = cron_days_of_month
  else
    fail 'One day field is required'
  end
end

Instance Attribute Details

#daysObject (readonly)

Returns the value of attribute days.



3
4
5
# File 'lib/cronline/cron.rb', line 3

def days
  @days
end

#hoursObject (readonly)

Returns the value of attribute hours.



3
4
5
# File 'lib/cronline/cron.rb', line 3

def hours
  @hours
end

#minutesObject (readonly)

Returns the value of attribute minutes.



3
4
5
# File 'lib/cronline/cron.rb', line 3

def minutes
  @minutes
end

#monthsObject (readonly)

Returns the value of attribute months.



3
4
5
# File 'lib/cronline/cron.rb', line 3

def months
  @months
end

#secondsObject (readonly)

Returns the value of attribute seconds.



3
4
5
# File 'lib/cronline/cron.rb', line 3

def seconds
  @seconds
end

#yearsObject (readonly)

Returns the value of attribute years.



3
4
5
# File 'lib/cronline/cron.rb', line 3

def years
  @years
end

Instance Method Details

#test?(time) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/cronline/cron.rb', line 33

def test?(time)
  @years.test?(time) && @months.test?(time) && @days.test?(time) &&
      @hours.test?(time) && @minutes.test?(time) && @seconds.test?(time)
end

#test_up_to_hours?(time) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/cronline/cron.rb', line 38

def test_up_to_hours?(time)
  @years.test?(time) && @months.test?(time) && @days.test?(time) &&
      @hours.test?(time)
end