Sha256: 892bc58a75b3127e521e8c0d8abc63fce6199e41226dc33eba46d308f4d6172c

Contents?: true

Size: 537 Bytes

Versions: 2

Compression:

Stored size: 537 Bytes

Contents

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|
        raise OverlappingShiftError if new_shift.overlaps?(shift)
        break @shifts.insert(i, new_shift) if shift.start_time > new_shift.end_time
      end
      @shifts << new_shift unless @shifts.size > starting_shift_count
      @shifts
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
time_clock-0.0.2 lib/time_clock/calendar.rb
time_clock-0.0.1 lib/time_clock/calendar.rb