-
Notifications
You must be signed in to change notification settings - Fork 3
/
TaskHelper.rb
92 lines (78 loc) · 1.9 KB
/
TaskHelper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class TaskSplitter
TaskExec = "/usr/local/bin/task"
@@userName = "arnaud"
attr_accessor :columns
def list
res = `#{TaskExec} long`.split("\n")
@columns = splitHead(res[2])
res
end
def detail(id)
`#{TaskExec} info #{id}`.split("\n")
end
def addTask(task, project, dueDate)
strProject = "project:#{project.strip}" unless project.nil? || project.strip.empty?
strDue = "due:#{dueDate.strip}" unless !dueDate.nil? || dueDate.strip.empty?
`#{TaskExec} add #{strProject} #{strDue} #{task}`
end
def doneTask(id)
`#{TaskExec} done #{id}`
end
def splitHead(header)
header.split.collect { |chars| chars.length }
end
def each_line(list_result)
# Clean useless lines
list = list_result.drop(3)
list.pop(2)
list.each do |line|
line.chomp!
next if line.empty?
each_column(line) do |val|
puts "column value : #{val}"
end unless block_given?
yield line if block_given?
end
end
def each_column(line)
prev = 0
annotation = false
@columns.each_with_index do |length, index|
endStr = prev + length
columnValue = line[prev..endStr].strip
yield columnValue if block_given?
annotation = annotation || (index == 0 && columnValue.empty?)
prev = endStr + 1
end
annotation
end
def fillTaskHolder (line)
holder = TaskHolder.new
holder.line = line
holder.columns = Array.new
holder.isAnnotation = each_column(line) do |value|
holder.columns.push value
end
holder
end
end
class TaskHolder
attr_accessor :line
attr_accessor :columns
attr_accessor :isAnnotation
end
=begin
# Sample
a = TaskSplitter.new
list = a.list
# Loop over line results
a.each_line(list) do |line|
puts "Line : #{line}"
# Loop over column value
isAnnotation = a.each_column(line) do |value|
puts "Column : #{value}"
end
puts "Annotation !" if isAnnotation
end
=end
nil