Class: Query::TimeAccumulator
- Inherits:
-
Object
- Object
- Query::TimeAccumulator
- Defined in:
- lib/query/time_accumulator.rb
Overview
singleton class to calculate time values for a given set of tasks
Class Method Summary collapse
-
.get_hours_beyond(tasks, next_time_frame) ⇒ Float
method to calculate the working hours of tasks starting during the requested time interval, but ending after.
-
.get_hours_during(tasks) ⇒ Float
method to calculate the working hours of tasks occurring during the requested time interval.
-
.get_hours_into(tasks, time_frame) ⇒ Float
method to calculate the working hours of tasks ending during the requested time interval, but starting before.
-
.get_interval_worktime(tasks, start_time, end_time, time_frame) ⇒ Hash
method to calculate the work time in the given time period.
Class Method Details
.get_hours_beyond(tasks, next_time_frame) ⇒ Float
method to calculate the working hours of tasks starting during the requested time interval, but ending after
56 57 58 59 60 61 62 63 |
# File 'lib/query/time_accumulator.rb', line 56 def self.get_hours_beyond(tasks, next_time_frame) total = 0.0 tasks.each { |task| total += next_time_frame - task.start_time } total = (total / 3600).round(2) end |
.get_hours_during(tasks) ⇒ Float
method to calculate the working hours of tasks occurring during the requested time interval
28 29 30 31 32 33 34 35 |
# File 'lib/query/time_accumulator.rb', line 28 def self.get_hours_during(tasks) total = 0.0 tasks.each { |task| total += task.end_time - task.start_time } total = (total / 3600).round(2) end |
.get_hours_into(tasks, time_frame) ⇒ Float
method to calculate the working hours of tasks ending during the requested time interval, but starting before
42 43 44 45 46 47 48 49 |
# File 'lib/query/time_accumulator.rb', line 42 def self.get_hours_into(tasks, time_frame) total = 0.0 tasks.each { |task| total += task.end_time - time_frame } total = (total / 3600).round(2) end |
.get_interval_worktime(tasks, start_time, end_time, time_frame) ⇒ Hash
method to calculate the work time in the given time period
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/query/time_accumulator.rb', line 13 def self.get_interval_worktime(tasks, start_time, end_time, time_frame) times = { :during => get_hours_during(tasks[:during]), :over => (tasks[:over].size > 0 ? time_frame : 0), :into => get_hours_into(tasks[:into], start_time), :beyond => get_hours_beyond(tasks[:beyond], end_time) } return times end |