Class: Sirius::TeachingTime

Inherits:
Object
  • Object
show all
Defined in:
lib/sirius/teaching_time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(teaching_period:, day:, parity:) ⇒ TeachingTime

Returns a new instance of TeachingTime.


9
10
11
12
13
# File 'lib/sirius/teaching_time.rb', line 9

def initialize(teaching_period:, day:, parity:)
  @teaching_period = teaching_period
  @day = day
  @parity = parity
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day


6
7
8
# File 'lib/sirius/teaching_time.rb', line 6

def day
  @day
end

#parityObject

Returns the value of attribute parity


7
8
9
# File 'lib/sirius/teaching_time.rb', line 7

def parity
  @parity
end

#teaching_periodObject (readonly)

Returns the value of attribute teaching_period


6
7
8
# File 'lib/sirius/teaching_time.rb', line 6

def teaching_period
  @teaching_period
end

Instance Method Details

#==(other) ⇒ Object


27
28
29
# File 'lib/sirius/teaching_time.rb', line 27

def ==(other)
  @teaching_period == other.teaching_period && @day == other.day && @parity == other.parity
end

#durationObject


23
24
25
# File 'lib/sirius/teaching_time.rb', line 23

def duration
  ends_at - starts_at
end

#ends_atObject


19
20
21
# File 'lib/sirius/teaching_time.rb', line 19

def ends_at
  @teaching_period.ends_at
end

#numeric_dayObject


31
32
33
# File 'lib/sirius/teaching_time.rb', line 31

def numeric_day
  Date::DAYS_INTO_WEEK[day] + 1
end

#starts_atObject


15
16
17
# File 'lib/sirius/teaching_time.rb', line 15

def starts_at
  @teaching_period.starts_at
end

#to_recurrence_rule(day_offset, schedule_ends_at) ⇒ Object


35
36
37
38
# File 'lib/sirius/teaching_time.rb', line 35

def to_recurrence_rule(day_offset, schedule_ends_at)
  teaching_day = (numeric_day + day_offset) % 7
  IceCube::Rule.weekly(week_frequency, :monday).day(teaching_day).until(schedule_ends_at)
end

#week_frequencyObject


40
41
42
43
44
45
46
# File 'lib/sirius/teaching_time.rb', line 40

def week_frequency
  if parity == 'both'
    1
  else
    2
  end
end