Class: TimeClock::Calendar
- Inherits:
-
Object
- Object
- TimeClock::Calendar
- Defined in:
- lib/time_clock/calendar.rb
Defined Under Namespace
Classes: OverlappingShiftError
Instance Attribute Summary collapse
-
#shifts ⇒ Object
readonly
Returns the value of attribute shifts.
Instance Method Summary collapse
- #add_shift(new_shift) ⇒ Object
-
#initialize ⇒ Calendar
constructor
A new instance of Calendar.
Constructor Details
#initialize ⇒ Calendar
Returns a new instance of Calendar.
8 9 10 |
# File 'lib/time_clock/calendar.rb', line 8 def initialize @shifts = [] end |
Instance Attribute Details
#shifts ⇒ Object (readonly)
Returns the value of attribute shifts.
6 7 8 |
# File 'lib/time_clock/calendar.rb', line 6 def shifts @shifts end |
Instance Method Details
#add_shift(new_shift) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# 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 |