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.



6
7
8
# File 'lib/clavius/schedule.rb', line 6

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

Instance Method Details

#active?(date) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/clavius/schedule.rb', line 34

def active?(date)
  date = date.to_date

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

#after(date) ⇒ Object



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

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

#before(date) ⇒ Object



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

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

#between(start_date, end_date) ⇒ Object



45
46
47
48
49
50
# File 'lib/clavius/schedule.rb', line 45

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

#days(number) ⇒ Object



41
42
43
# File 'lib/clavius/schedule.rb', line 41

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