Module: Query
- Defined in:
- lib/query/query.rb,
lib/query/time_accumulator.rb
Overview
This module holds the classes and methods for queries regarding the data
Defined Under Namespace
Classes: TimeAccumulator
Class Attribute Summary collapse
- .data ⇒ BaseHandler readonly
Class Method Summary collapse
-
.collect_tasks_beyond(start_time, end_time, all_task) ⇒ Hash
method to collect all task that start in the time interval but do not end in the requested interval.
-
.collect_tasks_during(start_time, end_time, all_task) ⇒ Hash
method to collect all task that occur during the time interval.
-
.collect_tasks_into(start_time, end_time, all_task) ⇒ Hash
method to collect all task that end in the time interval but were started before the requested interval.
-
.collect_tasks_over(start_time, end_time, all_task) ⇒ Hash
method to collect all task that start before the time interval but do not end in the time interval.
-
.get_data(id, start_time, end_time) ⇒ Hash
method to collect all tasks of a person in a given time interval.
-
.get_monthly_worktime(id, start_time, end_time) ⇒ Hash
method to retrieve the worktime for a person for the given month.
-
.get_time_worktime(id, start_time, end_time) ⇒ Hash
method to retrieve the worktime for a person for the given time interval.
-
.get_weekly_worktime(id, start_time, end_time) ⇒ Hash
method to retrieve the worktime for a person for the given week.
-
.initialize_repository(data) ⇒ Object
singleton method to initialize the data repository with the provided data.
-
.task_ends_after?(task, date_value) ⇒ Boolean
method to check if a given task ends after the specified date.
-
.task_starts_before?(task, date_value) ⇒ Boolean
method to check if a given task starts before the specified date.
-
.time_lies_in_interval?(time, start_time, end_time) ⇒ Boolean
method to determine if the point in time lies within the time interval given by the data values.
Class Attribute Details
Class Method Details
.collect_tasks_beyond(start_time, end_time, all_task) ⇒ Hash
method to collect all task that start in the time interval but do not end in the requested interval
124 125 126 127 128 129 |
# File 'lib/query/query.rb', line 124 def self.collect_tasks_beyond(start_time, end_time, all_task) all_task.select { |task| time_lies_in_interval?(task.start_time, start_time, end_time) && task_ends_after?(task, end_time) } end |
.collect_tasks_during(start_time, end_time, all_task) ⇒ Hash
method to collect all task that occur during the time interval
79 80 81 82 83 84 |
# File 'lib/query/query.rb', line 79 def self.collect_tasks_during(start_time, end_time, all_task) all_task.select { |task| !task_starts_before?(task, start_time) && !task_ends_after?(task, end_time) } end |
.collect_tasks_into(start_time, end_time, all_task) ⇒ Hash
method to collect all task that end in the time interval but were started before the requested interval
109 110 111 112 113 114 |
# File 'lib/query/query.rb', line 109 def self.collect_tasks_into(start_time, end_time, all_task) all_task.select { |task| task_starts_before?(task, start_time) && time_lies_in_interval?(task.end_time, start_time, end_time) } end |
.collect_tasks_over(start_time, end_time, all_task) ⇒ Hash
method to collect all task that start before the time interval but do not end in the time interval
94 95 96 97 98 99 |
# File 'lib/query/query.rb', line 94 def self.collect_tasks_over(start_time, end_time, all_task) all_task.select { |task| task_starts_before?(task, start_time) && task_ends_after?(task, end_time) } end |
.get_data(id, start_time, end_time) ⇒ Hash
method to collect all tasks of a person in a given time interval
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/query/query.rb', line 18 def self.get_data(id, start_time, end_time) all_task = Query.data.get_tasks_to_person(id) tasks = { :during => collect_tasks_during(start_time, end_time, all_task), :over => collect_tasks_over(start_time, end_time, all_task), :into => collect_tasks_into(start_time, end_time, all_task), :beyond => collect_tasks_beyond(start_time, end_time, all_task) } return tasks end |
.get_monthly_worktime(id, start_time, end_time) ⇒ Hash
method to retrieve the worktime for a person for the given month
46 47 48 49 50 51 |
# File 'lib/query/query.rb', line 46 def self.get_monthly_worktime(id, start_time, end_time) days_in_month = Time.days_in_month(start_time.year,start_time.month) tasks = get_data(id, start_time, end_time) TimeAccumulator.get_interval_worktime(tasks, start_time, end_time, (days_in_month * 24)) end |
.get_time_worktime(id, start_time, end_time) ⇒ Hash
method to retrieve the worktime for a person for the given time interval
60 61 62 63 64 |
# File 'lib/query/query.rb', line 60 def self.get_time_worktime(id, start_time, end_time) tasks = get_data(id, start_time, end_time) TimeAccumulator.get_interval_worktime(tasks, start_time, end_time, (end_time - start_time) / 60 / 60) end |
.get_weekly_worktime(id, start_time, end_time) ⇒ Hash
method to retrieve the worktime for a person for the given week
35 36 37 38 |
# File 'lib/query/query.rb', line 35 def self.get_weekly_worktime(id, start_time, end_time) tasks = get_data(id, start_time, end_time) TimeAccumulator.get_interval_worktime(tasks, start_time, end_time, (7*24)) end |
.initialize_repository(data) ⇒ Object
singleton method to initialize the data repository with the provided data
68 69 70 |
# File 'lib/query/query.rb', line 68 def self.initialize_repository(data) @data = data end |
.task_ends_after?(task, date_value) ⇒ Boolean
method to check if a given task ends after the specified date
158 159 160 |
# File 'lib/query/query.rb', line 158 def self.task_ends_after?(task, date_value) task.end_time > date_value end |
.task_starts_before?(task, date_value) ⇒ Boolean
method to check if a given task starts before the specified date
148 149 150 |
# File 'lib/query/query.rb', line 148 def self.task_starts_before?(task, date_value) task.start_time < date_value end |
.time_lies_in_interval?(time, start_time, end_time) ⇒ Boolean
method to determine if the point in time lies within the time interval given by the data values
138 139 140 |
# File 'lib/query/query.rb', line 138 def self.time_lies_in_interval?(time, start_time, end_time) time > start_time && time < end_time end |