Class: Elected::Scheduler::Schedule

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/elected/scheduler/schedule.rb

Constant Summary collapse

FIELDS =
{ seconds: :sec, minutes: :min, hours: :hour, days: :day, months: :month, dows: :wday }.freeze
ABBR_DAYNAMES =
%w{ sun mon tue wed thu fri sat }.freeze
DAYNAMES =
%w{ sunday monday tuesday wednesday thursday friday saturday }.freeze
MONTHNAMES =
%w{ '' january february march april may june july august september october november december }.freeze
ABBR_MONTHNAMES =
%w{ '' jan feb mar apr may jun jul aug sep oct nov dec }.freeze
MIN_NUMBERS =
{ seconds: 0, minutes: 0, hours: 0, days: 1, months: 1, dows: 0 }.freeze
MAX_NUMBERS =
{ seconds: 59, minutes: 59, hours: 23, days: 31, months: 12, dows: 6 }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Schedule

Returns a new instance of Schedule.



22
23
24
25
# File 'lib/elected/scheduler/schedule.rb', line 22

def initialize(options = {})
  @options = options
  setup *(FIELDS.keys)
end

Class Method Details

.defaultsObject



18
19
20
# File 'lib/elected/scheduler/schedule.rb', line 18

def self.defaults
  @defaults ||= { seconds: [0] }
end

Instance Method Details

#matches?(time) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/elected/scheduler/schedule.rb', line 27

def matches?(time)
  FIELDS.all? { |field, meth| match? field, time.send(meth) }
end

#to_cron_sObject Also known as: to_s, inspect



31
32
33
# File 'lib/elected/scheduler/schedule.rb', line 31

def to_cron_s
  FIELDS.keys.map { |field| get_cron_s(field) }.join(' ')
end