Class: Clavius::Schedule

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/clavius/schedule.rb

Instance Method Summary collapse

Constructor Details

#initialize(&config) ⇒ Schedule

Returns a new instance of Schedule.



8
9
10
# File 'lib/clavius/schedule.rb', line 8

def initialize(&config)
  @configuration = Configuration.new(&config)
end

Instance Method Details

#active?(date) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/clavius/schedule.rb', line 36

def active?(date)
  date = date.to_date

  (weekdays.include?(date.wday) || included.include?(date)) &&
    !excluded.include?(date)
end

#after(date) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/clavius/schedule.rb', line 27

def after(date)
  date
    .to_date
    .next_day
    .upto(Time::HEAT_DEATH)
    .lazy
    .select(&method(:active?))
end

#before(date) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/clavius/schedule.rb', line 18

def before(date)
  date
    .to_date
    .prev_day
    .downto(Time::BIG_BANG)
    .lazy
    .select(&method(:active?))
end

#between(start_date, end_date) ⇒ Object



47
48
49
50
51
52
# File 'lib/clavius/schedule.rb', line 47

def between(start_date, end_date)
  start_date
    .to_date
    .upto(end_date.to_date.prev_day)
    .select(&method(:active?))
end

#days(number) ⇒ Object



43
44
45
# File 'lib/clavius/schedule.rb', line 43

def days(number)
  Calculation::DaysFrom.new(self, number)
end