Class: Wheneverd::DSL::PeriodStrategy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/wheneverd/dsl/period_strategy/base.rb

Overview

Base class for period parsing strategies.

Each strategy handles a specific type of period value (Duration, String, Symbol, Array) and converts it into a trigger object.

Constant Summary collapse

DAY_SECONDS =
60 * 60 * 24
CALENDAR_SYMBOLS =
%i[
  hour day month year weekday weekend
  monday tuesday wednesday thursday friday saturday sunday
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ Base

Returns a new instance of Base.

Parameters:

  • path (String)

    schedule path for error reporting



21
22
23
# File 'lib/wheneverd/dsl/period_strategy/base.rb', line 21

def initialize(path:)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/wheneverd/dsl/period_strategy/base.rb', line 18

def path
  @path
end

Instance Method Details

#handles?(_period) ⇒ Boolean

Check if this strategy handles the given period type.

Parameters:

  • period (Object)

    the period value

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/wheneverd/dsl/period_strategy/base.rb', line 29

def handles?(_period)
  raise NotImplementedError, "#{self.class} must implement #handles?"
end

#parse(_period, at_times:) ⇒ Wheneverd::Trigger::Interval, Wheneverd::Trigger::Calendar

Parse the period into a trigger.

Parameters:

  • period (Object)

    the period value

  • at_times (Array<String>)

    normalized at: times

Returns:

Raises:



39
40
41
# File 'lib/wheneverd/dsl/period_strategy/base.rb', line 39

def parse(_period, at_times:)
  raise NotImplementedError, "#{self.class} must implement #parse"
end