class ScheduleDay

Attributes

periods[R]

Gets all of the periods in this schedule day.

schedule_day[R]

Returns the letter of the schedule day for the ScheduleDay object. @return [String] the letter

Public Class Methods

new(sd, periods) click to toggle source
# File lib/rhs-schedule/scheduleday.rb, line 9
def initialize(sd, periods)
  @schedule_day = sd
  @periods = periods
end

Public Instance Methods

set_periods(new_periods) click to toggle source

Sets the period list as given, after checking to make sure there are no holes in the schedule. If there are it returns false and does not set the schedule.

@param new_periods [Array<Period>] the new period list @return [nil]

# File lib/rhs-schedule/scheduleday.rb, line 19
def set_periods(new_periods)
  # Check start and end
  raise InvalidPeriodList, 'First and/or last periods are missing!' unless new_periods.first.start_time.strftime(TIME_FORMAT) == '08:40 AM' and new_periods.last.end_time.strftime(TIME_FORMAT) == '03:00 PM'
  
  # Check for gaps
  prev_time = '08:40 AM'
  new_periods.each do |p|
    if p.start_time.strftime(TIME_FORMAT) == prev_time
      prev_time = p.end_time.strftime(TIME_FORMAT)
      next
    end
    raise InvalidPeriodList, "There is a gap in the period list at #{p.start_time.strftime(TIME_FORMAT)}"
  end
  
  # No gaps, go ahead
  @periods = new_periods
end
to_s() click to toggle source

Returns short summary of schedule day, including letter, number of periods, and then a list of the periods.

# File lib/rhs-schedule/scheduleday.rb, line 38
def to_s
  to_return = ["#{@schedule_day}-Day: #{@periods.length} periods"]
  @periods.each do |p|
    to_return << " -#{p.to_s}"
  end
  to_return << "\n"

  to_return.join("\n")
end

Private Instance Methods

add_period(period) click to toggle source
# File lib/rhs-schedule/scheduleday.rb, line 49
def add_period(period)
  @periods << period
end
sort_periods() click to toggle source
# File lib/rhs-schedule/scheduleday.rb, line 53
def sort_periods
  @periods.sort! { |a, b| a.start_time <=> b.start_time }
end