Class: TimeClock::Comparison

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

Defined Under Namespace

Classes: NilCalendarError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time, end_time, calendar = TimeClock.default_calendar) ⇒ Comparison

Returns a new instance of Comparison.

Raises:



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

def initialize(start_time, end_time, calendar=TimeClock.default_calendar)
  raise NilCalendarError unless calendar
  @start_time, @end_time, @calendar = start_time.to_time, end_time.to_time, calendar
end

Instance Attribute Details

#calendarObject (readonly)

Returns the value of attribute calendar.



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

def calendar
  @calendar
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



6
7
8
# File 'lib/time_clock/comparison.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/comparison.rb', line 6

def start_time
  @start_time
end

Instance Method Details

#periodObject



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

def period
  @period ||= Shift.new(earlier_time, later_time)
end

#secondsObject



17
18
19
20
21
# File 'lib/time_clock/comparison.rb', line 17

def seconds
  calendar.shifts.inject(0) do |total_seconds, shift|
    total_seconds + period.overlapping_seconds(shift)
  end
end