Add todo.txt pom and its dependencies
This commit is contained in:
parent
1e7adfa51c
commit
af5315c5b9
10 changed files with 403 additions and 0 deletions
63
.todo.actions.d/pom/lib/task.rb
Normal file
63
.todo.actions.d/pom/lib/task.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require 'rainbow'
|
||||
|
||||
class Task
|
||||
|
||||
attr_accessor :text
|
||||
attr_accessor :index
|
||||
attr_accessor :pomodori
|
||||
attr_accessor :planned
|
||||
|
||||
POMO_REGEXP = / \(#pomo: (\d+)\/(\d+)\)$/
|
||||
PRIORITY_REGEXP = /^\([A-Z]+\) /
|
||||
STATUS_COLORS = {
|
||||
new: :white,
|
||||
planned: :green,
|
||||
in_progress: :yellow,
|
||||
completed: :blue,
|
||||
underestimated: :red
|
||||
}
|
||||
|
||||
def initialize index, text
|
||||
@index = index.to_i
|
||||
if text =~ POMO_REGEXP
|
||||
@pomodori, @planned = text.match(POMO_REGEXP)[1].to_i, text.match(POMO_REGEXP)[2].to_i
|
||||
else
|
||||
@pomodori, @planned = 0, 0
|
||||
end
|
||||
@text = text.gsub(POMO_REGEXP, '').gsub(PRIORITY_REGEXP, '')
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{text} (#pomo: #{pomodori}/#{planned})"
|
||||
end
|
||||
|
||||
def add_pomo
|
||||
@pomodori += 1
|
||||
end
|
||||
|
||||
def plan planned
|
||||
@planned = planned.to_i
|
||||
end
|
||||
|
||||
def puts_highlighted
|
||||
return if blank?(text)
|
||||
print "#{index} #{text} "
|
||||
color = STATUS_COLORS[self.status]
|
||||
puts Rainbow("(#pomo: #{pomodori}/#{planned})").send(color)
|
||||
end
|
||||
|
||||
def status
|
||||
return :new if pomodori == 0 && planned == 0
|
||||
return :planned if pomodori == 0 && planned != 0
|
||||
return :completed if pomodori == planned
|
||||
return :in_progress if pomodori != 0 && planned != 0 && pomodori < planned
|
||||
return :underestimated if pomodori != 0 && pomodori > planned
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def blank?(string)
|
||||
string == nil || string == ""
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue