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.2.0'
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.
37 38 39 40 |
# File 'lib/taskish.rb', line 37 def initialize @data = {} yield self if block_given? end |
Instance Method Details
#done ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/taskish.rb', line 42 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
50 51 52 53 54 55 56 |
# File 'lib/taskish.rb', line 50 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
58 59 60 |
# File 'lib/taskish.rb', line 58 def key?(key) @data.key? key end |
#parse(lines) ⇒ Object
62 63 64 65 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 |
# File 'lib/taskish.rb', line 62 def parse(lines) project = nil lines.each_with_index do |l, idx| idx += 1 l.chomp! if l =~ /^(\S.+):$/ #warn "PROJECT => #{ $1 }" if key? $1 warn "line ##{idx} - project '#{ $1 }' already exists; skipping" project = nil else @data[ $1 ] = [] project = $1 end 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
92 93 94 95 96 |
# File 'lib/taskish.rb', line 92 def readlines(fn) raise(ArgumentError, 'file does not exist') if ( fn.nil? || !File.exist?(fn) ) parse( File.open(fn).readlines ) self end |