Class: TimeClock::Comparison
- Inherits:
-
Object
- Object
- TimeClock::Comparison
- Defined in:
- lib/time_clock/comparison.rb
Defined Under Namespace
Classes: NilCalendarError
Instance Attribute Summary collapse
-
#calendar ⇒ Object
readonly
Returns the value of attribute calendar.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #days ⇒ Object
-
#initialize(start_time, end_time, calendar = TimeClock.default_calendar) ⇒ Comparison
constructor
A new instance of Comparison.
- #period ⇒ Object
- #seconds ⇒ Object
Constructor Details
#initialize(start_time, end_time, calendar = TimeClock.default_calendar) ⇒ Comparison
Returns a new instance of Comparison.
8 9 10 11 12 13 |
# 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 |
Instance Attribute Details
#calendar ⇒ Object (readonly)
Returns the value of attribute calendar.
6 7 8 |
# File 'lib/time_clock/comparison.rb', line 6 def calendar @calendar end |
#end_time ⇒ Object (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_time ⇒ Object (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
#days ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
15 16 17 |
# File 'lib/time_clock/comparison.rb', line 15 def period @period ||= Shift.new(earlier_time, later_time) end |
#seconds ⇒ Object
19 20 21 22 23 |
# 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 |