class When::Cron

Public Class Methods

new(cron) click to toggle source
# File lib/when-cron/cron/cron.rb, line 11
def initialize(cron)
  @cron = cron
end
valid(cron) click to toggle source
# File lib/when-cron/cron/cron.rb, line 7
def self.valid(cron)
  new(cron) if valid?(cron)
end
valid?(cron) click to toggle source
# File lib/when-cron/cron/cron.rb, line 3
def self.valid?(cron)
  Validator.valid?(cron)
end

Public Instance Methods

==(time) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

parse(string) click to toggle source
# File lib/when-cron/cron/cron.rb, line 34
def parse(string)
  strings = string.split(' ')
  @minute = CronPart.new(strings[0])
  @hour   = CronPart.new(strings[1])
  @day    = CronPart.new(strings[2])
  @month  = CronPart.new(strings[3])
  @wday   = CronPart.new(strings[4])
end