Class: Wheneverd::Trigger::Calendar

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/wheneverd/trigger/calendar.rb

Overview

A calendar trigger, rendered as one or more OnCalendar= lines.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(on_calendar:) ⇒ Calendar

Returns a new instance of Calendar.

Parameters:

  • on_calendar (Array<String>)

    non-empty calendar specs



13
14
15
16
17
18
19
20
# File 'lib/wheneverd/trigger/calendar.rb', line 13

def initialize(on_calendar:)
  unless on_calendar.is_a?(Array) && !on_calendar.empty? &&
         on_calendar.all? { |v| v.is_a?(String) && !v.strip.empty? }
    raise ArgumentError, "on_calendar must be a non-empty Array of non-empty Strings"
  end

  @on_calendar = on_calendar.map(&:strip)
end

Instance Attribute Details

#on_calendarArray<String> (readonly)

Returns calendar specs (already in systemd OnCalendar format).

Returns:

  • (Array<String>)

    calendar specs (already in systemd OnCalendar format)



10
11
12
# File 'lib/wheneverd/trigger/calendar.rb', line 10

def on_calendar
  @on_calendar
end

Instance Method Details

#signatureString

Returns stable signature for unit naming.

Returns:

  • (String)

    stable signature for unit naming



28
29
30
# File 'lib/wheneverd/trigger/calendar.rb', line 28

def signature
  "calendar:#{on_calendar.sort.join('|')}"
end

#systemd_timer_linesArray<String>

Returns systemd [Timer] lines for this trigger.

Returns:

  • (Array<String>)

    systemd [Timer] lines for this trigger



23
24
25
# File 'lib/wheneverd/trigger/calendar.rb', line 23

def systemd_timer_lines
  on_calendar.map { |spec| "OnCalendar=#{spec}" }
end