class TimeClock::Calendar

Attributes

shifts[R]

Public Class Methods

new() click to toggle source
# File lib/time_clock/calendar.rb, line 8
def initialize
  @shifts = []
end

Public Instance Methods

add_shift(new_shift) click to toggle source
# File lib/time_clock/calendar.rb, line 12
def add_shift(new_shift)
  starting_shift_count = @shifts.size
  shifts.each_with_index do |shift, index|
    raise OverlappingShiftError if new_shift.overlaps?(shift)
    break shifts.insert(index, new_shift) if shift.start_time > new_shift.end_time
  end
  shifts << new_shift unless shifts.size > starting_shift_count
  shifts
end