lib/time_clock/calendar.rb in time_clock-0.0.2 vs lib/time_clock/calendar.rb in time_clock-0.0.3

- old
+ new

@@ -1,22 +1,23 @@ module TimeClock class Calendar + class OverlappingShiftError < ArgumentError; end attr_reader :shifts def initialize @shifts = [] end def add_shift(new_shift) starting_shift_count = @shifts.size - @shifts.each_with_index do |shift, i| + shifts.each_with_index do |shift, index| raise OverlappingShiftError if new_shift.overlaps?(shift) - break @shifts.insert(i, new_shift) if shift.start_time > new_shift.end_time + 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 + shifts << new_shift unless shifts.size > starting_shift_count + shifts end end end \ No newline at end of file