Class: Taskish
- Inherits:
-
Object
- Object
- Taskish
- Defined in:
- lib/taskish.rb,
lib/taskish/app.rb,
lib/taskish/task.rb,
lib/taskish/version.rb
Overview
:nodoc:
Defined Under Namespace
Constant Summary collapse
- VERSION =
'0.3'
Instance Method Summary collapse
- #done ⇒ Object
- #due(due = :today) ⇒ Object
-
#initialize {|_self| ... } ⇒ Taskish
constructor
A new instance of Taskish.
- #key?(key) ⇒ Boolean
- #parse(lines) ⇒ Object
- #readlines(fn) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Taskish
Returns a new instance of Taskish.
41 42 43 44 |
# File 'lib/taskish.rb', line 41 def initialize @data = {} yield self if block_given? end |
Instance Method Details
#done ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/taskish.rb', line 46 def done task_list = [] @data.each_pair do |project, tasks| tasks.each { |task| task_list << task if task.done? } end task_list end |
#due(due = :today) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/taskish.rb', line 54 def due( due = :today ) task_list = [] @data.each_pair do |project, tasks| tasks.each { |task| task_list << task if ( task.due?(due) and !task.done? ) } end task_list.sort_by { |t| t.due } end |
#key?(key) ⇒ Boolean
62 63 64 |
# File 'lib/taskish.rb', line 62 def key?(key) @data.key? key end |
#parse(lines) ⇒ Object
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 |
# File 'lib/taskish.rb', line 66 def parse(lines) project = nil lines.each_with_index do |l, idx| idx += 1 l.chomp! if l =~ /^(\S.+):$/ if key? $1 # warn "line ##{idx} - duplicate project '#{ $1 }'" else @data[ $1 ] = [] end project = $1 elsif l =~ /^\s+\-\s+(.*)$/ #warn "TASK => #{ $1 }" if project @data[project] << Task.new(project, $1) else warn "line ##{idx} - no project for task; skipping (#{l})" end elsif l =~ /^\S*$/ #warn "SKIP! (#{l})" next else warn "invalid line ##{idx} - (#{l})" end end end |
#readlines(fn) ⇒ Object
94 95 96 97 98 |
# File 'lib/taskish.rb', line 94 def readlines(fn) raise(ArgumentError, 'file does not exist') if ( fn.nil? || !File.exist?(fn) ) parse( File.open(fn).readlines ) self end |