class TimeClock::Comparison
Attributes
calendar[R]
end_time[R]
start_time[R]
Public Class Methods
new(start_time, end_time, calendar=TimeClock.default_calendar)
click to toggle source
# File lib/time_clock/comparison.rb, line 8 def initialize(start_time, end_time, calendar=TimeClock.default_calendar) raise NilCalendarError unless calendar @start_time = start_time.to_time @end_time = end_time_from_value(end_time) @calendar = calendar end
Public Instance Methods
days()
click to toggle source
# File lib/time_clock/comparison.rb, line 25 def days dates = Set.new calendar.shifts.each do |shift| if period.overlapping_seconds(shift) > 0 dates.add shift.start_time.to_date dates.add shift.end_time.to_date end end dates.size end
period()
click to toggle source
# File lib/time_clock/comparison.rb, line 15 def period @period ||= Shift.new(earlier_time, later_time) end
seconds()
click to toggle source
# File lib/time_clock/comparison.rb, line 19 def seconds calendar.shifts.inject(0) do |total_seconds, shift| total_seconds + period.overlapping_seconds(shift) end end
Private Instance Methods
earlier_time()
click to toggle source
# File lib/time_clock/comparison.rb, line 47 def earlier_time start_time < end_time ? start_time : end_time end
end_time_from_value(value)
click to toggle source
# File lib/time_clock/comparison.rb, line 38 def end_time_from_value(value) case value when Time, ActiveSupport::TimeWithZone value.to_time when Date (value + 1).to_time end end
later_time()
click to toggle source
# File lib/time_clock/comparison.rb, line 51 def later_time end_time > start_time ? end_time : start_time end