Time et todolist OK

Version quasi-utilisable. Reste à gérer la GUI.
This commit is contained in:
Yann Esposito 2009-06-08 12:16:29 +02:00
parent a4cd356ea9
commit f5fc8ced30
3 changed files with 32 additions and 32 deletions

View file

@ -84,7 +84,7 @@ class Task
@tags =raw_input.scan( @@TagsRegExp).map{ |x| x[0] } @tags =raw_input.scan( @@TagsRegExp).map{ |x| x[0] }
# somehow special for the priority # somehow special for the priority
@priority= raw_input.scan( /!/ ).length - raw_input.scan( /\?/ ).length @priority=raw_input.scan( /!/ ).length - raw_input.scan( /\?/ ).length
@description=raw_input.gsub( @description=raw_input.gsub(
Regexp.union(@@ContextsRegExp, @@ProjectsRegExp, Regexp.union(@@ContextsRegExp, @@ProjectsRegExp,

View file

@ -6,13 +6,13 @@ require 'chronic'
require 'time' require 'time'
class TaskTime class TaskTime
@creation_date # creation date of the task @created # creation date of the task
@start_date # date at with the task began (hour,minute,second) @started # date at with the task began (hour,minute,second)
@done_date # date at which the task was done @done # date at which the task was done
@due_date # due date for the task @due # due date for the task
@duration # time spend for finish that task @duration # time spend for finish that task
# can be set by the user to be # can be set by the user to be
# different than (@done_date - @start_date) # different than (@done - @started)
@max_duration # maximal duration for that task @max_duration # maximal duration for that task
@min_duration # minimal duration for that task @min_duration # minimal duration for that task
@ -21,40 +21,40 @@ class TaskTime
@@StdTokenRegExp=Regexp.new(%{(\\w+|"[^"]*")}) @@StdTokenRegExp=Regexp.new(%{(\\w+|"[^"]*")})
# Notes # Notes
@@TimeShort=Regexp.new(%{#(#{@@StdTokenRegExp.inspect[1..-2]}(,|->))?#{@@StdTokenRegExp.inspect[1..-2]}}) @@TimeShort=Regexp.new(%{#(#{@@StdTokenRegExp.inspect[1..-2]}(,|->))?#{@@StdTokenRegExp.inspect[1..-2]}})
@@TimeVerbose=Regexp.new(%{ (created|done|due|duration|max_duration|min_duration):(#{@@StdTokenRegExp.inspect[1..-2]})} ) @@TimeVerbose=Regexp.new(%{ (created|done|due|duration|max_duration|min_duration):#{@@StdTokenRegExp.inspect[1..-2]}} )
@@Time=Regexp.union(@@TimeShort,@@TimeVerbose) @@Time=Regexp.union(@@TimeShort,@@TimeVerbose)
def to_s def to_s
res=%{created:"#{@creation_date}"} res=%{created:"#{@created}"}
if ( @start_date ) : res+=%{,started:"#{@start_date}"} end if ( @started ) : res<<=%{,started:"#{@started}"} end
if ( @done_date ) : res+=%{,done:"#{@done_date}"} end if ( @done ) : res<<=%{,done:"#{@done}"} end
if ( @due_date ) : res+=%{,due:"#{@due_date}"} end if ( @due ) : res<<=%{,due:"#{@due}"} end
if ( @duration ) : res+=%{,duration:"#{@duration}"} end if ( @duration ) : res<<=%{,duration:"#{@duration}"} end
if ( @max_duration ): res+=%{,max_duration:"#{@duration}"} end if ( @max_duration ): res<<=%{,max_duration:"#{@duration}"} end
if ( @min_duration ): res+=%{,min_duration:"#{@duration}"} end if ( @min_duration ): res<<=%{,min_duration:"#{@duration}"} end
return res return res
end end
def to_detailled_s def to_detailled_s
res=%{ created:#{@creation_date}} res=%{ created:#{@created}}
if ( @start_date ) : res+="\n"+%{ started:#{@start_date}} end if ( @started ) : res<<="\n"+%{ started: #{@started}} end
if ( @done_date ) : res+="\n"+%{ done:#{@done_date}} end if ( @done ) : res<<="\n"+%{ done: #{@done}} end
if ( @due_date ) : res+="\n"+%{ due:#{@due_date}} end if ( @due ) : res<<="\n"+%{ due: #{@due}} end
if ( @duration ) : res+="\n"+%{ duration:#{@duration}} end if ( @duration ) : res<<="\n"+%{ duration: #{@duration}} end
if ( @max_duration ): res+="\n"+%{max_duration:#{@duration}} end if ( @max_duration ): res<<="\n"+%{max_duration: #{@duration}} end
if ( @min_duration ): res+="\n"+%{min_duration:#{@duration}} end if ( @min_duration ): res<<="\n"+%{min_duration: #{@duration}} end
return res return res
end end
def from_s( raw_input ) def from_s( raw_input )
scanned_input=raw_input.scan( @@TimeShort ) scanned_input=raw_input.scan( @@TimeShort )
str_of_start_date = scanned_input.map{ |x| x[3] } str_of_start_date = scanned_input.map{ |x| x[3] }
@due_date = Chronic.parse(str_of_start_date) @due = Chronic.parse(str_of_start_date)
str_of_due_date = scanned_input.map{ |x| x[1] } str_of_due = scanned_input.map{ |x| x[1] }
@start_date = Chronic.parse(str_of_due_date) @started = Chronic.parse(str_of_due)
raw_input.scan( @@TimeVerbose ).each do |x| raw_input.scan( @@TimeVerbose ).each do |x|
timeValue=Chronic.parse(x[1]) timeValue=Chronic.parse(x[1])
if timeValue=nil: if timeValue==nil:
timeValue=Time.parse(x[1]) timeValue=Time.parse(x[1])
end end
eval %{@#{x[0]}=timeValue} eval %{@#{x[0]}=timeValue}
@ -63,10 +63,10 @@ class TaskTime
end end
def initialize ( raw_input=nil ) def initialize ( raw_input=nil )
@creation_date=Time.now @created=Time.now
@start_date = nil @started = nil
@done_date = nil @done = nil
@due_date = nil @due = nil
@duration = nil @duration = nil
@max_duration = nil @max_duration = nil
@min_duration = nil @min_duration = nil

View file

@ -26,8 +26,8 @@ class TodoList
begin begin
f=File.open(filename, 'r') f=File.open(filename, 'r')
while (line=f.readline) while (line=f.readline)
puts "ajout de "+line puts "ajout de "+line[4..-2]
addTask( Task.new( line ) ) addTask( Task.new(line[4..-2]) )
end end
rescue Errno::ENOENT rescue Errno::ENOENT
puts "no such file #{filename}" puts "no such file #{filename}"
@ -70,7 +70,7 @@ if __FILE__ == $0:
filename = defaultTaskFile filename = defaultTaskFile
end end
todoList.load filename todoList.load filename
when /^quit$/ when /^q(uit)?$/
break break
else else
print "/!\\ Commande inconnue /!\\\n" print "/!\\ Commande inconnue /!\\\n"