syc-task 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,6 +83,7 @@ module Syctask
83
83
  title = titles[index] ? titles[index] : "Meeting #{index}"
84
84
  @meetings << Syctask::Meeting.new(busy, title)
85
85
  end
86
+ raise Exception, "Busy times have to be within work time" unless within?(@meetings, @starts, @ends)
86
87
  @tasks = tasks
87
88
  end
88
89
 
@@ -167,6 +168,20 @@ module Syctask
167
168
 
168
169
  private
169
170
 
171
+ # Checks if meetings are within work times. Returns true if fullfilled
172
+ # otherwise false
173
+ def within?(meetings, starts, ends)
174
+ meetings.each do |meeting|
175
+ return false if meeting.starts.h < starts.h
176
+ return false if meeting.starts.h == starts.h and
177
+ meeting.starts.m < starts.m
178
+ return false if meeting.ends.h > ends.h
179
+ return false if meeting.ends.h == ends.h and
180
+ meeting.ends.m > ends.m
181
+ end
182
+ true
183
+ end
184
+
170
185
  # Colors the time line free time green, busy time red and tasks blue. The
171
186
  # past time is colored black
172
187
  def colorize(time_line)
@@ -183,9 +198,14 @@ module Syctask
183
198
  # future part.
184
199
  def split_time_line(time_line)
185
200
  time = Time.now
186
- offset = (time.hour - @starts.h) * 4 + time.min.div(15)
187
- past = time_line.slice(0,offset)
188
- future = time_line.slice(offset, time_line.size - offset)
201
+ if time.hour < @starts.h
202
+ past = ""
203
+ future = time_line
204
+ else
205
+ offset = (time.hour - @starts.h) * 4 + time.min.div(15)
206
+ past = time_line.slice(0,offset)
207
+ future = time_line.slice(offset, time_line.size - offset)
208
+ end
189
209
  [past, future]
190
210
  end
191
211
 
data/lib/syctask/task.rb CHANGED
@@ -9,6 +9,8 @@ module Syctask
9
9
  # about a task.
10
10
  class Task
11
11
 
12
+ include Comparable
13
+
12
14
  # Holds the options of the task.
13
15
  # Options are
14
16
  # * description - additional information about the task
@@ -50,6 +52,17 @@ module Syctask
50
52
  @id == other.id and @dir == other.dir
51
53
  end
52
54
 
55
+ # Compares this Task to the other task and compares them regarding the ID
56
+ # and the dir. If ID is equal then dir is compared
57
+ def <=>(other)
58
+ id_compare = @id.to_i <=> other.id.to_i
59
+ if id_compare == 0
60
+ @dir <=> other.dir
61
+ else
62
+ id_compare
63
+ end
64
+ end
65
+
53
66
  # Updates the task with new values. Except for note and tags which are
54
67
  # supplemented with the new values and not overridden.
55
68
  def update(options)
@@ -60,7 +60,7 @@ module Syctask
60
60
  next if not all and task.done?
61
61
  tasks << task if task.matches?(filter)
62
62
  end
63
- tasks
63
+ tasks.sort
64
64
  end
65
65
 
66
66
  # Updates the task with the given id in the given directory dir with the
@@ -1,5 +1,5 @@
1
1
  # Syctask provides functions for managing tasks in a task list
2
2
  module Syctask
3
3
  #Holds the version number of syctask
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syc-task
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-11 00:00:00.000000000 Z
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake