Class: Syctask::Schedule
- Inherits:
-
Object
- Object
- Syctask::Schedule
- Defined in:
- lib/syctask/schedule.rb
Overview
Schedule represents a working day with a start and end time, meeting times and titles and tasks. Tasks can also be associated to meetings as in an agenda. Invokation example
work = ["8","30","18","45"]
busy = [["9","0","10","0"],["11","30","12","15"]]
titles = ["Ruby class room training","Discuss Ruby"]
tasks = [task1,task2,task3,task4,task5,task6]
schedule = Syctask::Schedule.new(work,busy,titles,tasks)
schedule.graph.each {|output| puts output}
This will create following output
Meetings
--------
A - Ruby class room training
B - Discuss Ruby
A B
xxoo/////xxx|-////oooooxoooo|---|---|---|---|
8 9 10 11 12 13 14 15 16 17 18 19
1 2 3 4 5
6
Tasks
-----
0 - 1: task1
1 - 2: task2
2 - 3: task3
3 - 4: task4
4 - 5: task5
5 - 6: task6
Subsequent tasks are are displayed in the graph alternating with x and o. Meetings are indicated with / and the start is marked with A, B and so on. Task IDs are shown below the graph. The graph will be printed colored. Meetings in red, free times in green and tasks in blue. The past time is shown in black.
Constant Summary collapse
- BUSY_COLOR =
Color of meetings
:red
- FREE_COLOR =
Color of free times
:green
- WORK_COLOR =
Color of tasks
:blue
- UNSCHEDULED_COLOR =
If tasks cannot be assigned to the working time this color is used
:yellow
- GRAPH_PATTERN =
Regex scans tasks and free times in the graph
/[\|-]+|\/+|[xo]+/
- BUSY_PATTERN =
Regex scans meetings in the graph
/\/+/
- FREE_PATTERN =
Regex scans free times in the graph
/[\|-]+/
- WORK_PATTERN =
Regex scans tasks in the graph
/[xo]+/
Instance Attribute Summary collapse
-
#ends ⇒ Object
readonly
End time of working day.
-
#meetings ⇒ Object
Meetings assigned to the work time.
-
#starts ⇒ Object
readonly
Start time of working day.
-
#tasks ⇒ Object
Tasks assigned to the work time.
Instance Method Summary collapse
-
#assign(assignments) ⇒ Object
Sets the assignments containing tasks that are assigned to meetings.
-
#get_times ⇒ Object
Retrieves the work and busy times transformed to the time line scale.
-
#graph ⇒ Object
graph first creates creates the time line.
-
#initialize(work_time, busy_time = [], titles = [], tasks = []) ⇒ Schedule
constructor
Creates a new Schedule and initializes work time, busy times, titles and tasks.
-
#meeting_caption ⇒ Object
Creates a meeting caption and returns it for printing.
-
#meeting_list ⇒ Object
Creates a meeting list for printing.
-
#time_caption ⇒ Object
Creates the time caption for the time line.
Constructor Details
#initialize(work_time, busy_time = [], titles = [], tasks = []) ⇒ Schedule
Creates a new Schedule and initializes work time, busy times, titles and tasks. Work time is mandatory, busy times, titles and tasks are optional. Values have to be provided as
-
work time: [start_hour, start_minute, end_hour, end_minute]
-
busy time: [[start_hour, start_minute, end_hour, end_minute],]
-
titles: [title,…]
-
tasks: [task,…]
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/syctask/schedule.rb', line 82 def initialize(work_time, busy_time=[], titles=[], tasks=[]) @starts = Syctask::Times.new([work_time[0], work_time[1]]) @ends = Syctask::Times.new([work_time[2], work_time[3]]) @meetings = [] titles ||= [] busy_time.each.with_index do |busy,index| title = titles[index] ? titles[index] : "Meeting #{index}" @meetings << Syctask::Meeting.new(busy, title) end raise Exception, "Busy times have to be within work time" unless within?(@meetings, @starts, @ends) @tasks = tasks end |
Instance Attribute Details
#ends ⇒ Object (readonly)
End time of working day
69 70 71 |
# File 'lib/syctask/schedule.rb', line 69 def ends @ends end |
#meetings ⇒ Object
Meetings assigned to the work time
71 72 73 |
# File 'lib/syctask/schedule.rb', line 71 def meetings @meetings end |
#starts ⇒ Object (readonly)
Start time of working day
67 68 69 |
# File 'lib/syctask/schedule.rb', line 67 def starts @starts end |
#tasks ⇒ Object
Tasks assigned to the work time
73 74 75 |
# File 'lib/syctask/schedule.rb', line 73 def tasks @tasks end |
Instance Method Details
#assign(assignments) ⇒ Object
Sets the assignments containing tasks that are assigned to meetings. Returns true if succeeds
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/syctask/schedule.rb', line 100 def assign(assignments) assignments.each do |assignment| number = assignment[0].upcase.ord - "A".ord return false if number < 0 or number > @meetings.size @meetings[number].tasks.clear assignment[1].split(',').each do |id| index = @tasks.find_index{|task| task.id == id.to_i} @meetings[number].tasks << @tasks[index] if index and @tasks[index] end @meetings[number].tasks.uniq! end true end |
#get_times ⇒ Object
Retrieves the work and busy times transformed to the time line scale
396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/syctask/schedule.rb', line 396 def get_times work_time = [@starts.h, @ends.round_up] meeting_times = [] @meetings.each do |meeting| meeting_time = Array.new(2) meeting_time[0] = hour_offset(@starts.h, meeting.starts.h) + minute_offset(meeting.starts.m) meeting_time[1] = hour_offset(@starts.h, meeting.ends.h) + minute_offset(meeting.ends.m) meeting_times << meeting_time end if @meetings times = [work_time, meeting_times] end |
#graph ⇒ Object
graph first creates creates the time line. Then the busy times are added. After that the tasks are added to the time line and the task caption and task list is created. graph returns the graph, task caption, task list and meeting list
-
time line
-
add meetings to time line
-
add tasks to time line
-
create task caption
-
create task list
-
create meeting caption
-
create meeting list
-
return time line, task caption, task list, meeting caption and meeting
list
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/syctask/schedule.rb', line 171 def graph work_time, meeting_times = get_times heading = sprintf("+++ %s - %s-%s +++", Time.now.strftime("%Y-%m-%d"), @starts.time.strftime("%H:%M"), @ends.time.strftime("%H:%M")).color(:blue) time_line = "|---" * (work_time[1]-work_time[0]) + "|" meeting_times.each do |time| time_line[time[0]..time[1]-1] = '/' * (time[1] - time[0]) end task_list, = assign_tasks_to_graph(time_line) [heading.center(80), meeting_list, , colorize(time_line), , , task_list] end |
#meeting_caption ⇒ Object
Creates a meeting caption and returns it for printing
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/syctask/schedule.rb', line 137 def work_time, meeting_times = get_times = "" meeting_number = "A" meeting_times.each do |times| << ' ' * (times[0] - .size) + meeting_number meeting_number.next! end sprintf("%s", ).color(:red) end |
#meeting_list ⇒ Object
Creates a meeting list for printing. Returns the meeting list
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/syctask/schedule.rb', line 115 def meeting_list list = sprintf("%s", "Meetings\n").color(:red) list << sprintf("%s", "--------\n").color(:red) meeting_number = "A" @meetings.each do |meeting| hint = "-" hint = "*" if time_between?(Time.now, meeting.starts.time, meeting.ends.time) list << sprintf("%s %s %s\n", meeting_number, hint, meeting.title).color(:red) meeting_number.next! meeting.tasks.each do |task| task_color = task.done? ? :green : :blue list << sprintf("%5s - %s\n", task.id, task.title).color(task_color) end end list end |
#time_caption ⇒ Object
Creates the time caption for the time line
149 150 151 152 153 154 155 156 |
# File 'lib/syctask/schedule.rb', line 149 def work_time = get_times[0] = "" work_time[0].upto(work_time[1]) do |time| << time.to_s + (time < 9 ? ' ' * 3 : ' ' * 2) end sprintf("%s", ) end |