Class: TimeClock::Shift

Inherits:
Object
  • Object
show all
Defined in:
lib/time_clock/shift.rb

Defined Under Namespace

Classes: EndTimeAfterStartTimeError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time, end_time) ⇒ Shift

Returns a new instance of Shift.



8
9
10
11
# File 'lib/time_clock/shift.rb', line 8

def initialize(start_time, end_time)
  raise EndTimeAfterStartTimeError unless end_time > start_time
  @start_time, @end_time = start_time.to_time, end_time.to_time
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



6
7
8
# File 'lib/time_clock/shift.rb', line 6

def end_time
  @end_time
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



6
7
8
# File 'lib/time_clock/shift.rb', line 6

def start_time
  @start_time
end

Instance Method Details

#==(value) ⇒ Object



21
22
23
# File 'lib/time_clock/shift.rb', line 21

def ==(value)
  start_time == value.start_time && end_time == value.end_time
end

#overlapping_seconds(shift) ⇒ Object



17
18
19
# File 'lib/time_clock/shift.rb', line 17

def overlapping_seconds(shift)
  [[end_time,shift.end_time].min - [start_time,shift.start_time].max,0].max
end

#overlaps?(shift) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/time_clock/shift.rb', line 13

def overlaps?(shift)
  start_time <= shift.end_time && end_time >= shift.start_time
end