Class: Wheneverd::DSL::PeriodParser

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

Overview

Converts DSL every(...) period values into trigger objects.

Supported period forms are described in the README.

Uses a strategy pattern to delegate parsing to specialized strategy classes:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ PeriodParser

Returns a new instance of PeriodParser.

Parameters:

  • path (String)

    schedule path for error reporting



20
21
22
# File 'lib/wheneverd/dsl/period_parser.rb', line 20

def initialize(path:)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/wheneverd/dsl/period_parser.rb', line 17

def path
  @path
end

Instance Method Details

#trigger_for(period, at:) ⇒ Wheneverd::Trigger::Interval, Wheneverd::Trigger::Calendar

Parameters:

Returns:



27
28
29
30
31
32
33
# File 'lib/wheneverd/dsl/period_parser.rb', line 27

def trigger_for(period, at:)
  at_times = AtNormalizer.normalize(at, path: path)
  strategy = PeriodStrategy.for(period, path: path)
  strategy.parse(period, at_times: at_times)
rescue Wheneverd::InvalidIntervalError => e
  raise InvalidPeriodError.new(e.message, path: path)
end