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
|
|
|
|
def initialize(description, note, contacts,
|
2009-05-22 14:45:53 +00:00
|
|
|
contexts, projects, dates, tags)
|
2009-05-18 09:39:17 +00:00
|
|
|
# the title of the task
|
|
|
|
@description=description
|
|
|
|
# list of additionnal informations about the note
|
|
|
|
# such as files (pdf, csv...)
|
|
|
|
# details concerning this task
|
|
|
|
@notes=notes
|
|
|
|
# list of contacts
|
|
|
|
@contacts=contacts
|
|
|
|
# list of contextes
|
|
|
|
@contexts=contexts
|
|
|
|
# list of projects
|
|
|
|
@projects=projects
|
|
|
|
# multiple date associated to a task
|
|
|
|
@dates=dates
|
2009-05-22 14:45:53 +00:00
|
|
|
# tags
|
|
|
|
@tags=tags
|
2009-05-18 09:39:17 +00:00
|
|
|
end
|
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
|
|
|
|
if (@contexts): res+=' ' + @contexts.map { |x| x.to_s }.join(" ") end
|
|
|
|
if (@projects): res+=' ' + @projects.map { |x| '['+x.to_s+']' }.join(" ") end
|
|
|
|
if (@contacts): res+=' ' + @contacts.map { |x| x.to_s }.join(" ") end
|
|
|
|
if (@dates): res+=' ' + @dates.to_s end
|
|
|
|
if (@tags): res+=' ' + '{' + @tags.map{ |x| x.to_s }.join(", ") + '}' end
|
|
|
|
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
|
|
|
|
@@StdTokenRegExp=/(\w+|"[^"]*")/
|
|
|
|
# Context
|
2009-05-26 13:40:53 +00:00
|
|
|
@@ContextsRegExp=Regexp.new(%{ @#{@@StdTokenRegExp.inspect}})
|
2009-05-22 14:45:53 +00:00
|
|
|
# Project
|
2009-05-26 13:40:53 +00:00
|
|
|
@@ProjectsRegExp=Regexp.new(%{\\[#{@@StdTokenRegExp.inspect}\\]})
|
2009-05-22 14:45:53 +00:00
|
|
|
# Contact
|
2009-05-26 13:40:53 +00:00
|
|
|
@@ContactsRegExp=Regexp.new(%{ (c|contact):#{@@StdTokenRegExp.inspect}})
|
2009-05-22 14:45:53 +00:00
|
|
|
# Notes
|
2009-05-26 13:40:53 +00:00
|
|
|
@@NotesRegExp=Regexp.new(%{\(#{@@StdTokenRegExp.inspect}\)})
|
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
|
|
|
|
|
|
|
current = Task.new("Coucou");
|
|
|
|
print current.to_s
|
|
|
|
print "\n"
|