Class: ScanSchedule::Repeat

Inherits:
Object
  • Object
show all
Defined in:
lib/domain/scan_schedule/repeat.rb

Constant Summary collapse

VALID_EVERY_VALUES =
%w[hour day week date-of-month day-of-month].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(every:, interval:, day_of_week: nil, date_of_month: nil, last_day_of_month: false, week_of_month: nil) ⇒ Repeat

Returns a new instance of Repeat.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/domain/scan_schedule/repeat.rb', line 9

def initialize(
  every:,
  interval:,
  day_of_week: nil,
  date_of_month: nil,
  last_day_of_month: false,
  week_of_month: nil
)
  @every = every
  @interval = interval
  @day_of_week = day_of_week
  @date_of_month = date_of_month
  @last_day_of_month = last_day_of_month
  @week_of_month = week_of_month

  validate!
end

Instance Attribute Details

#date_of_monthObject

Returns the value of attribute date_of_month.



5
6
7
# File 'lib/domain/scan_schedule/repeat.rb', line 5

def date_of_month
  @date_of_month
end

#day_of_weekObject

Returns the value of attribute day_of_week.



5
6
7
# File 'lib/domain/scan_schedule/repeat.rb', line 5

def day_of_week
  @day_of_week
end

#everyObject

Returns the value of attribute every.



5
6
7
# File 'lib/domain/scan_schedule/repeat.rb', line 5

def every
  @every
end

#intervalObject

Returns the value of attribute interval.



5
6
7
# File 'lib/domain/scan_schedule/repeat.rb', line 5

def interval
  @interval
end

#last_day_of_monthObject

Returns the value of attribute last_day_of_month.



5
6
7
# File 'lib/domain/scan_schedule/repeat.rb', line 5

def last_day_of_month
  @last_day_of_month
end

#week_of_monthObject

Returns the value of attribute week_of_month.



5
6
7
# File 'lib/domain/scan_schedule/repeat.rb', line 5

def week_of_month
  @week_of_month
end

Class Method Details

.from_json(data) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/domain/scan_schedule/repeat.rb', line 37

def self.from_json(data)
  ScanSchedule::Repeat.new(
    day_of_week: data['dayOfWeek'],
    every: data['every'],
    interval: data['interval'],
    last_day_of_month: data['lastDayOfMonth'],
    week_of_month: data['weekOfMonth']
  )
end

Instance Method Details

#to_json(*_args) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/domain/scan_schedule/repeat.rb', line 27

def to_json(*_args)
  {
    dayOfWeek: day_of_week,
    every:,
    interval:,
    lastDayOfMonth: last_day_of_month,
    weekOfMonth: week_of_month
  }.to_json
end