taskish 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in taskish.gemspec
4
+ gemspec
data/HISTORY ADDED
@@ -0,0 +1,3 @@
1
+ 2011-06-23 v0.0.1
2
+ - Initial prototype release.
3
+
@@ -0,0 +1,25 @@
1
+ = Taskish - Pending
2
+
3
+ == USAGE
4
+
5
+ Taskish.new do |taskish|
6
+
7
+ # Read task file
8
+ taskish.readlines('todo.txt')
9
+
10
+ # Find tasks due today
11
+ taskish.due(:today)
12
+
13
+ # Find tasks due within the next week
14
+ taskish.due(:week)
15
+
16
+ end
17
+
18
+ == HOME PAGE
19
+
20
+ https://github.com/blairc/taskish
21
+
22
+ == AUTHOR
23
+
24
+ Blair Christensen, <blair.christensen@gmail.com>
25
+
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rdoc-readme/rake_task'
4
+
5
+ RDoc::Readme::RakeTask.new 'lib/taskish.rb', 'README.rdoc'
6
+
7
+ task :default => :test
8
+
9
+ Rake::TestTask.new { |t|
10
+ t.libs = [ 'test' ]
11
+ t.pattern = 'test/*_test.rb'
12
+ t.verbose = true
13
+ t.warning = true
14
+ }
15
+
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'taskish'
4
+
5
+ if __FILE__ == $0
6
+ # TODO Extract to class?
7
+ cmd, file = ARGV.shift, ARGV.shift
8
+ unless cmd && file
9
+ warn "USAGE: #{ File.basename(__FILE__) } { today | week } <file>"
10
+ exit
11
+ end
12
+ Taskish.new do |taskish|
13
+ case cmd
14
+ when 'today'
15
+ taskish.readlines(file)
16
+ puts "TODAY\n~~~~~"
17
+ taskish.due(:today).each { |task| puts task }
18
+ when 'week'
19
+ taskish.readlines(file)
20
+ puts "WEEK\n~~~~"
21
+ taskish.due(:week).each { |task| puts task }
22
+ else
23
+ warn "unknown command: #{cmd}"
24
+ exit 1
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,85 @@
1
+ require 'taskish/task'
2
+ require 'taskish/version'
3
+
4
+ # = Taskish - Pending
5
+ #
6
+ # == USAGE
7
+ #
8
+ # Taskish.new do |taskish|
9
+ #
10
+ # # Read task file
11
+ # taskish.readlines('todo.txt')
12
+ #
13
+ # # Find tasks due today
14
+ # taskish.due(:today)
15
+ #
16
+ # # Find tasks due within the next week
17
+ # taskish.due(:week)
18
+ #
19
+ # end
20
+ #
21
+ # == HOME PAGE
22
+ #
23
+ # https://github.com/blairc/taskish
24
+ #
25
+ # == AUTHOR
26
+ #
27
+ # Blair Christensen, <blair.christensen@gmail.com>
28
+ #
29
+ class Taskish
30
+ def initialize
31
+ @data = {}
32
+ yield self if block_given?
33
+ end
34
+
35
+ def due( due = :today )
36
+ task_list = []
37
+ @data.each_pair do |project, tasks|
38
+ tasks.each { |task| task_list << task if task.due?(due) }
39
+ end
40
+ task_list.sort_by { |t| t.due }
41
+ end
42
+
43
+ def key?(key)
44
+ @data.key? key
45
+ end
46
+
47
+ def parse(lines)
48
+ project = nil
49
+ lines.each_with_index do |l, idx|
50
+ idx += 1
51
+ l.chomp!
52
+ if l =~ /^(\S.+):$/
53
+ #warn "PROJECT => #{ $1 }"
54
+ if key? $1
55
+ warn "line ##{idx} - project '#{ $1 }' already exists; skipping"
56
+ project = nil
57
+ else
58
+ @data[ $1 ] = []
59
+ project = $1
60
+ end
61
+ elsif l =~ /^\s+\-\s+(.*)$/
62
+ #warn "TASK => #{ $1 }"
63
+ if project
64
+ @data[project] << Task.new(project, $1)
65
+ else
66
+ warn "line ##{idx} - no project for task; skipping (#{l})"
67
+ end
68
+ elsif l =~ /^\S*$/
69
+ #warn "SKIP! (#{l})"
70
+ next
71
+ else
72
+ warn "invalid line ##{idx} - (#{l})"
73
+ end
74
+ end
75
+ end
76
+
77
+ def readlines(fn)
78
+ raise(ArgumentError, 'file does not exist') if ( fn.nil? || !File.exist?(fn) )
79
+ parse( File.open(fn).readlines )
80
+ self
81
+ end
82
+
83
+ end # class Taskish
84
+
85
+
@@ -0,0 +1,63 @@
1
+ require 'date'
2
+
3
+ class Taskish # :nodoc:
4
+
5
+ # = Taskish::Task - A single task
6
+ #
7
+ # == USAGE
8
+ #
9
+ # Taskish::Task.new(project, task) do |task|
10
+ # ...
11
+ # end
12
+ #
13
+ class Task
14
+ def initialize(project, task)
15
+ raise(ArgumentError, 'invalid project') if ( project.nil? || project.empty? )
16
+ raise(ArgumentError, 'invalid task') if ( task.nil? || task.empty? )
17
+ @data = { :project => project, :task => task }
18
+ if task =~ /^(.+?)\s+\@due(.*?)\s*$/
19
+ @data[:task] = $1
20
+ @data[:due] = $2.empty? ? Date.today : Date.parse( $2.gsub(/^\(/, '').gsub(/\)$/, '') )
21
+ else
22
+ end
23
+ yield self if block_given?
24
+ end
25
+
26
+ def due
27
+ @data[:due] || nil
28
+ end
29
+
30
+ def due?(date)
31
+ return false unless key? :due
32
+ case date
33
+ when :today
34
+ return @data[:due] <= Date.today
35
+ when :week
36
+ d = Date.today + 7
37
+ week = DateTime.new( d.year, d.mon, d.mday, 23, 59 )
38
+ return @data[:due] <= week
39
+ else
40
+ warn "invalid due date specification - '#{date}'"
41
+ end
42
+ false
43
+ end
44
+
45
+ def key?(key)
46
+ @data.key? key
47
+ end
48
+
49
+ def task
50
+ @data[:task]
51
+ end
52
+
53
+ def to_s
54
+ s = sprintf( "%-20s\t%s" % [ @data[:project], @data[:task] ] )
55
+ if key? :due
56
+ s = sprintf( "%s @due(%s)" % [ s, @data[:due] ] )
57
+ end
58
+ s
59
+ end
60
+ end # class Taskish::Task
61
+
62
+ end # class Taskish
63
+
@@ -0,0 +1,3 @@
1
+ class Taskish # :nodoc:
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'taskish/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'taskish'
7
+ s.version = Taskish::VERSION
8
+ s.authors = ['blair christensen.']
9
+ s.email = ['blair.christensen@gmail.com']
10
+ s.homepage = 'https://github.com/blairc/taskish'
11
+ s.summary = %q{Pending}
12
+ s.description = %q{Pending}
13
+
14
+ s.rubyforge_project = 'taskish'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency( %q<rdoc-readme>, [ '>=0.1.1' ] )
22
+ s.add_development_dependency( %q<shoulda>, [ '>=2.11.3' ] )
23
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class TaskTest < Test::Unit::TestCase
4
+
5
+ context '#initialize()' do
6
+ should 'raise ArgumentError if nil project' do
7
+ assert_raise(ArgumentError, 'invalid project') { Taskish::Task.new(nil, "t") }
8
+ end
9
+ should 'raise ArgumentError if empty project' do
10
+ assert_raise(ArgumentError, 'invalid project') { Taskish::Task.new('', "t") }
11
+ end
12
+ should 'raise ArgumentError if nil task' do
13
+ assert_raise(ArgumentError, 'invalid task') { Taskish::Task.new("p", nil) }
14
+ end
15
+ should 'raise ArgumentError if empty task' do
16
+ assert_raise(ArgumentError, 'invalid task') { Taskish::Task.new("p", '') }
17
+ end
18
+ should 'return object if no block given' do
19
+ assert_instance_of Taskish::Task, Taskish::Task.new("p", "t")
20
+ end
21
+ should 'work as a block' do
22
+ Taskish::Task.new("p", "t") do |task|
23
+ assert_instance_of Taskish::Task, task
24
+ end
25
+ end
26
+ end
27
+
28
+ end # class TaskTest
29
+
@@ -0,0 +1,4 @@
1
+ Project 1:
2
+ - Task 1-A @due
3
+ - Task 1-B
4
+
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class TaskishTest < Test::Unit::TestCase
4
+
5
+ context '#initialize()' do
6
+ should 'return object if no block given' do
7
+ assert_instance_of Taskish, Taskish.new
8
+ end
9
+ should 'work as a block' do
10
+ Taskish.new do |taskish|
11
+ assert_instance_of Taskish, taskish
12
+ end
13
+ end
14
+ end
15
+
16
+ context '#readlines()' do
17
+ setup do
18
+ @taskish = Taskish.new
19
+ @bad_file = File.join( File.dirname(__FILE__), 'no_such_file.txt' )
20
+ @good_file = File.join( File.dirname(__FILE__), 'taskish.txt' )
21
+ end
22
+
23
+ should 'raise ArgumentError if file does not exist' do
24
+ assert_raise(ArgumentError, 'no such file') { @taskish.readlines(nil) }
25
+ assert_raise(ArgumentError, 'no such file') { @taskish.readlines('') }
26
+ assert_raise(ArgumentError, 'no such file') { @taskish.readlines(@bad_file) }
27
+ end
28
+
29
+ should 'not return self after reading file' do
30
+ assert_equal @taskish, @taskish.readlines(@good_file)
31
+ end
32
+ end
33
+
34
+ end # class TaskishTest
35
+
@@ -0,0 +1,7 @@
1
+ $: << File.expand_path( File.join( File.dirname(__FILE__), '..', 'lib' ) )
2
+
3
+ require 'rubygems'
4
+ require 'shoulda'
5
+ require 'test/unit'
6
+ require 'taskish'
7
+
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class VersionTest < Test::Unit::TestCase
4
+
5
+ should 'have expected version' do
6
+ assert_equal '0.0.1', Taskish::VERSION
7
+ end
8
+
9
+ end # class VersionTest
10
+
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taskish
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - blair christensen.
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-06-23 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rdoc-readme
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 1
31
+ - 1
32
+ version: 0.1.1
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: shoulda
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 2
45
+ - 11
46
+ - 3
47
+ version: 2.11.3
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: Pending
51
+ email:
52
+ - blair.christensen@gmail.com
53
+ executables:
54
+ - taskish
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - .gitignore
61
+ - Gemfile
62
+ - HISTORY
63
+ - README.rdoc
64
+ - Rakefile
65
+ - bin/taskish
66
+ - lib/taskish.rb
67
+ - lib/taskish/task.rb
68
+ - lib/taskish/version.rb
69
+ - taskish.gemspec
70
+ - test/task_test.rb
71
+ - test/taskish.txt
72
+ - test/taskish_test.rb
73
+ - test/test_helper.rb
74
+ - test/version_test.rb
75
+ has_rdoc: true
76
+ homepage: https://github.com/blairc/taskish
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: taskish
103
+ rubygems_version: 1.3.7
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Pending
107
+ test_files:
108
+ - test/task_test.rb
109
+ - test/taskish.txt
110
+ - test/taskish_test.rb
111
+ - test/test_helper.rb
112
+ - test/version_test.rb