Class: When::Cron

Inherits:
Object
  • Object
show all
Defined in:
lib/when-cron/cron/cron.rb,
lib/when-cron/cron/validator.rb

Defined Under Namespace

Classes: Validator

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cron) ⇒ Cron

Returns a new instance of Cron.



11
12
13
# File 'lib/when-cron/cron/cron.rb', line 11

def initialize(cron)
  @cron = cron
end

Class Method Details

.valid(cron) ⇒ Object



7
8
9
# File 'lib/when-cron/cron/cron.rb', line 7

def self.valid(cron)
  new(cron) if valid?(cron)
end

.valid?(cron) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.valid?(cron)
  Validator.valid?(cron)
end

Instance Method Details

#==(time) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/when-cron/cron/cron.rb', line 15

def ==(time)
  @parsed ||= parse(@cron)

  @minute == time.min &&
  @hour   == time.hour &&
  @month  == time.month &&
  day_of_week_and_or_day_of_month?(time)
end

#day_of_week_and_or_day_of_month?(time) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/when-cron/cron/cron.rb', line 24

def day_of_week_and_or_day_of_month?(time)
  if @day.wildcard? || @wday.wildcard?
    @day == time.day && @wday == time.wday
  else
    @day == time.day || @wday == time.wday
  end
end