2009-05-18 09:39:17 +00:00
|
|
|
#!/usr/bin/env ruby
|
2009-05-18 14:57:11 +00:00
|
|
|
#
|
|
|
|
require 'taskTime.rb'
|
|
|
|
require 'contact.rb'
|
2009-05-18 09:39:17 +00:00
|
|
|
|
|
|
|
class Task
|
2009-06-02 15:43:28 +00:00
|
|
|
def initialize(raw_input)
|
2009-05-18 09:39:17 +00:00
|
|
|
@notes=[]
|
|
|
|
@contacts=[]
|
|
|
|
@contexts=[]
|
|
|
|
@projects=[]
|
2009-05-22 14:45:53 +00:00
|
|
|
@tags=[]
|
|
|
|
@priority=0
|
2009-05-18 09:39:17 +00:00
|
|
|
@dates=TaskTime.new()
|
2009-06-02 15:43:28 +00:00
|
|
|
from_s(raw_input)
|
2009-05-18 09:39:17 +00:00
|
|
|
end
|
2009-05-18 14:57:11 +00:00
|
|
|
def to_s
|
2009-06-02 15:43:28 +00:00
|
|
|
res=@description
|
2009-06-03 10:19:42 +00:00
|
|
|
if (@contexts.length>0): res+=' ' + @contexts.map { |x| x.to_s }.join(" ") end
|
|
|
|
if (@projects.length>0): res+=' ' + @projects.map { |x| '['+x.to_s+']' }.join(" ") end
|
2009-06-03 11:35:31 +00:00
|
|
|
if (@priority != 0): res+=' /'+ @priority.to_s + '\\' end
|
|
|
|
if (@notes.length>0): res+=' ' + @notes.map { |x| '('+x.to_s+')' }.join(" ") end
|
2009-06-03 10:19:42 +00:00
|
|
|
if (@contacts.length>0): res+=' ' + @contacts.map { |x| x.to_s }.join(" ") end
|
|
|
|
if (@dates): res+=' ' + @dates.to_s end
|
|
|
|
if (@tags.length>0): res+=' ' + '{' + @tags.map{ |x| x.to_s }.join(", ") + '}' end
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_detailled_s
|
|
|
|
res='desc: '+@description
|
|
|
|
if (@contexts.length>0):
|
|
|
|
res+="\n contexts:" + @contexts.map { |x| x.to_s }.join(" ")
|
|
|
|
end
|
|
|
|
if (@projects.length>0):
|
|
|
|
res+="\n projects:" + @projects.map { |x| '['+x.to_s+']' }.join(" ")
|
|
|
|
end
|
2009-06-03 11:35:31 +00:00
|
|
|
if (@priority != 0):
|
|
|
|
res+="\n priority: " + @priority.to_s
|
|
|
|
end
|
|
|
|
if (@notes.length>0):
|
|
|
|
res+="\n notes : " + @notes.map { |x| '('+x.to_s+')' }.join(" ")
|
|
|
|
end
|
2009-06-03 10:19:42 +00:00
|
|
|
if (@contacts.length>0):
|
|
|
|
res+="\n contacts:" + @contacts.map { |x| x.to_s }.join(" ")
|
|
|
|
end
|
|
|
|
if (@dates):
|
|
|
|
res+="\n dates :\n" + @dates.to_detailled_s
|
|
|
|
end
|
|
|
|
if (@tags.length>0):
|
|
|
|
res+="\n tags :" + '{' + @tags.map{ |x| x.to_s }.join(", ") + '}'
|
|
|
|
end
|
2009-06-02 15:43:28 +00:00
|
|
|
return res
|
2009-05-18 14:57:11 +00:00
|
|
|
end
|
2009-05-22 14:45:53 +00:00
|
|
|
|
2009-05-26 13:40:53 +00:00
|
|
|
# -- constant class variable for each part
|
|
|
|
# -- of the regular expressions
|
|
|
|
|
2009-05-22 14:45:53 +00:00
|
|
|
# Regular Expressions for that class
|
2009-06-03 10:19:42 +00:00
|
|
|
@@StdTokenRegExp=Regexp.new(%{(\\w+|"[^"]*")})
|
2009-05-22 14:45:53 +00:00
|
|
|
# Context
|
2009-06-03 10:19:42 +00:00
|
|
|
@@ContextsRegExp=Regexp.new(%{ @#{@@StdTokenRegExp.inspect[1..-2]}})
|
2009-05-22 14:45:53 +00:00
|
|
|
# Project
|
2009-06-03 10:19:42 +00:00
|
|
|
@@ProjectsRegExp=Regexp.new(%{\\[#{@@StdTokenRegExp.inspect[1..-2]}\\]})
|
2009-05-22 14:45:53 +00:00
|
|
|
# Contact
|
2009-06-03 10:19:42 +00:00
|
|
|
@@ContactsRegExp=Regexp.new(%{ (c|contact):#{@@StdTokenRegExp.inspect[1..-2]}})
|
2009-05-22 14:45:53 +00:00
|
|
|
# Notes
|
2009-06-03 11:35:31 +00:00
|
|
|
@@NotesRegExp=Regexp.new(%{\\(([^\)]*)\\)})
|
2009-05-22 14:45:53 +00:00
|
|
|
|
|
|
|
def from_s( raw_input )
|
|
|
|
|
2009-06-02 15:43:28 +00:00
|
|
|
@contexts=raw_input.scan(@@ContextsRegExp).map{ |x| x[0] }
|
|
|
|
@projects=raw_input.scan(@@ProjectsRegExp).map{ |x| x[0] }
|
|
|
|
@contacts=raw_input.scan(@@ContactsRegExp).map{ |x| x[1] }
|
|
|
|
@notes =raw_input.scan( @@NotesRegExp).map{ |x| x[0] }
|
2009-05-22 14:45:53 +00:00
|
|
|
|
|
|
|
# somehow special for the priority
|
2009-06-02 15:43:28 +00:00
|
|
|
@priority= raw_input.scan( /!/ ).length - raw_input.scan( /\?/ ).length
|
2009-05-22 14:45:53 +00:00
|
|
|
|
|
|
|
@description=raw_input.gsub(
|
2009-06-02 15:43:28 +00:00
|
|
|
Regexp.union(@@ContextsRegExp, @@ProjectsRegExp,
|
|
|
|
@@ContactsRegExp, @@NotesRegExp,
|
|
|
|
/!/, /\?/, @dates.regexp),"")
|
|
|
|
@dates=TaskTime.new(raw_input)
|
2009-05-18 14:57:11 +00:00
|
|
|
end
|
2009-05-18 09:39:17 +00:00
|
|
|
end
|
2009-06-02 15:43:28 +00:00
|
|
|
|
2009-06-03 11:35:31 +00:00
|
|
|
task = Task.new("")
|
|
|
|
while true:
|
|
|
|
print "> "
|
|
|
|
task.from_s( STDIN.gets.chomp )
|
|
|
|
print "------------\n"
|
|
|
|
print task.to_s
|
|
|
|
print "\n------------\n"
|
|
|
|
print task.to_detailled_s
|
|
|
|
print "\n------------\n"
|
|
|
|
end
|