sculd 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +9 -1
- data/Gemfile +2 -2
- data/Rakefile +27 -9
- data/VERSION +1 -1
- data/bin/sculd +8 -7
- data/lib/sculd.rb +2 -2
- data/lib/sculd/manager.rb +65 -29
- data/lib/sculd/plan.rb +26 -18
- data/lib/sculd/plan/deadline.rb +15 -8
- data/lib/sculd/plan/reminder.rb +7 -4
- data/lib/sculd/plan/schedule.rb +6 -3
- data/lib/sculd/plan/todo.rb +17 -9
- data/test/helper.rb +17 -0
- data/{spec/schedule → test/schedule/empty}/empty.dat +0 -0
- data/{spec/schedule → test/schedule/error}/error.dat +0 -0
- data/test/schedule/normal/a.dat +10 -0
- data/test/schedule/normal/b.dat +5 -0
- data/test/test_deadline.rb +47 -0
- data/test/test_manager.rb +114 -0
- data/test/test_plan.rb +97 -0
- data/test/test_reminder.rb +38 -0
- data/test/test_schedule.rb +30 -0
- data/test/test_todo.rb +50 -0
- metadata +24 -52
- data/lib/sculd/event.rb +0 -23
- data/lib/sculd/task.rb +0 -18
- data/sculd.gemspec +0 -92
- data/spec/command_spec.rb +0 -7
- data/spec/deadline_spec.rb +0 -46
- data/spec/event_spec.rb +0 -35
- data/spec/job_spec.rb +0 -7
- data/spec/manager_spec.rb +0 -131
- data/spec/plan_spec.rb +0 -85
- data/spec/reminder_spec.rb +0 -38
- data/spec/schedule/schedule.dat +0 -5
- data/spec/schedule_spec.rb +0 -30
- data/spec/sculd_spec.rb +0 -4
- data/spec/spec_helper.rb +0 -12
- data/spec/todo_spec.rb +0 -48
data/CHANGES
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
= sdrt changelog
|
2
2
|
|
3
|
-
== Master
|
3
|
+
== Master
|
4
|
+
|
5
|
+
== Version 0.1.0 [2013-05-17] released
|
6
|
+
* Use test-unit alternatively to rspec.
|
7
|
+
* Enable to use directory, ~/.sculd alternatively to ~/.sculd.dat
|
8
|
+
* Change output format.
|
9
|
+
* Change library interfaces.
|
10
|
+
|
11
|
+
== Version 0.0.3 [2013-04-18] released
|
4
12
|
* Options -s, -t, -i is made into bin/dates command.
|
5
13
|
* Use /usr/bin/env ruby in bin/dates, alternatively to /usr/bin/ruby.
|
6
14
|
|
data/Gemfile
CHANGED
@@ -6,11 +6,11 @@ source "http://rubygems.org"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem "rspec", "~> 2.12.0"
|
9
|
+
#gem "rspec", "~> 2.12.0"
|
10
10
|
gem "rdoc", "~> 3.12"
|
11
11
|
gem "bundler", "~> 1.3.5"
|
12
12
|
gem "jeweler", "~> 1.8.4"
|
13
13
|
gem "simplecov", ">= 0"
|
14
14
|
gem "highline", ">= 1.6.15"
|
15
|
-
gem "psych", ">= 0"
|
15
|
+
#gem "psych", ">= 0"
|
16
16
|
end
|
data/Rakefile
CHANGED
@@ -25,18 +25,36 @@ Jeweler::Tasks.new do |gem|
|
|
25
25
|
end
|
26
26
|
Jeweler::RubygemsDotOrgTasks.new
|
27
27
|
|
28
|
-
require 'rspec/core'
|
29
|
-
require 'rspec/core/rake_task'
|
30
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
-
end
|
28
|
+
#require 'rspec/core'
|
29
|
+
#require 'rspec/core/rake_task'
|
30
|
+
#RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
# spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
#end
|
33
|
+
#
|
34
|
+
#RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
# spec.rcov = true
|
37
|
+
#end
|
38
|
+
#
|
39
|
+
#task :default => :spec
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
require 'rake/testtask'
|
42
|
+
Rake::TestTask.new(:test) do |test|
|
43
|
+
test.libs << 'lib' << 'test'
|
44
|
+
test.pattern = 'test/**/test_*.rb'
|
45
|
+
test.verbose = true
|
37
46
|
end
|
38
47
|
|
39
|
-
|
48
|
+
#require 'rcov/rcovtask'
|
49
|
+
#Rcov::RcovTask.new do |test|
|
50
|
+
# test.libs << 'test'
|
51
|
+
# test.pattern = 'test/**/test_*.rb'
|
52
|
+
# test.verbose = true
|
53
|
+
# test.rcov_opts << '--exclude "gems/*"'
|
54
|
+
#end
|
55
|
+
|
56
|
+
task :default => :test
|
57
|
+
|
40
58
|
|
41
59
|
require 'rdoc/task'
|
42
60
|
Rake::RDocTask.new do |rdoc|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bin/sculd
CHANGED
@@ -5,7 +5,8 @@
|
|
5
5
|
# Events include schedule and deadline(start and end).
|
6
6
|
# Tasks include deadline, reminder and todo.
|
7
7
|
|
8
|
-
SCULD_DAT = "#{ENV['HOME']}/.sculd.dat"
|
8
|
+
#SCULD_DAT = "#{ENV['HOME']}/.sculd.dat"
|
9
|
+
SCULD_DIR = "#{ENV['HOME']}/.sculd"
|
9
10
|
|
10
11
|
require "pp"
|
11
12
|
require "optparse"
|
@@ -18,7 +19,7 @@ OPTS = {}
|
|
18
19
|
op = OptionParser.new
|
19
20
|
op.on("-e day", "--event days", "Show events."){|v| OPTS[:event] = v.to_i}
|
20
21
|
op.on("-t num", "--task num" , "Show tasks." ){|v| OPTS[:task ] = v.to_i}
|
21
|
-
op.on("-f file", "--file datafile", "Indicate file."){|v| OPTS[:file] = v}
|
22
|
+
#op.on("-f file", "--file datafile", "Indicate file."){|v| OPTS[:file] = v}
|
22
23
|
op.parse!(ARGV)
|
23
24
|
|
24
25
|
#num_day = ARGV.shift.to_i
|
@@ -31,18 +32,18 @@ if (( OPTS[:event] == 0) &&( OPTS[:task ] == 0))
|
|
31
32
|
exit
|
32
33
|
end
|
33
34
|
|
34
|
-
file = OPTS[:file]
|
35
|
-
file ||= SCULD_DAT
|
35
|
+
#file = OPTS[:file]
|
36
|
+
#file ||= SCULD_DAT
|
36
37
|
|
37
|
-
unless FileTest.exist?
|
38
|
+
unless FileTest.exist? SCULD_DIR
|
38
39
|
# lines = File.open(file, "r").readlines
|
39
40
|
#rescue
|
40
|
-
puts "Not found #{
|
41
|
+
puts "Not found #{SCULD_DIR}. Exit."
|
41
42
|
exit
|
42
43
|
end
|
43
44
|
|
44
45
|
begin
|
45
|
-
sm = Sculd::Manager.new(
|
46
|
+
sm = Sculd::Manager.new(SCULD_DIR)
|
46
47
|
rescue Sculd::Manager::LoadError
|
47
48
|
puts "Exit."
|
48
49
|
exit
|
data/lib/sculd.rb
CHANGED
data/lib/sculd/manager.rb
CHANGED
@@ -5,7 +5,7 @@ require "date"
|
|
5
5
|
require "sculd.rb"
|
6
6
|
|
7
7
|
require "rubygems"
|
8
|
-
gem "highline"
|
8
|
+
#gem "highline"
|
9
9
|
require "highline"
|
10
10
|
|
11
11
|
#
|
@@ -18,9 +18,12 @@ class Sculd::Manager
|
|
18
18
|
class LoadError < Exception; end
|
19
19
|
|
20
20
|
#
|
21
|
-
def initialize(
|
22
|
-
@
|
23
|
-
|
21
|
+
def initialize(dir, io = $stdout)
|
22
|
+
@source_dir = dir
|
23
|
+
@plans = []
|
24
|
+
Dir.glob("#{@source_dir}/*").each do |file|
|
25
|
+
load_file(file, io)
|
26
|
+
end
|
24
27
|
end
|
25
28
|
|
26
29
|
def show(num_event, num_task, io = $stdout)
|
@@ -32,31 +35,35 @@ class Sculd::Manager
|
|
32
35
|
|
33
36
|
# read, parse file and set data to @events and @tasks.
|
34
37
|
def load_file(file, io = $stdio)
|
35
|
-
@plans = []
|
36
38
|
|
37
39
|
File.open(file, "r").readlines.each_with_index do |line, index|
|
38
40
|
begin
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
when
|
49
|
-
|
50
|
-
when "+"
|
51
|
-
plan_type = Sculd::Plan::Todo
|
52
|
-
option = 7 if option == 0
|
41
|
+
elems = Sculd::Plan.parse(line, io)
|
42
|
+
next unless elems[:type]
|
43
|
+
case elems[:type]
|
44
|
+
when Sculd::Plan::Schedule::SYMBOL_CHAR
|
45
|
+
plan_class = Sculd::Plan::Schedule
|
46
|
+
when Sculd::Plan::Deadline::SYMBOL_CHAR
|
47
|
+
plan_class = Sculd::Plan::Deadline
|
48
|
+
when Sculd::Plan::Reminder::SYMBOL_CHAR
|
49
|
+
plan_class = Sculd::Plan::Reminder
|
50
|
+
when Sculd::Plan::Todo::SYMBOL_CHAR
|
51
|
+
plan_class = Sculd::Plan::Todo
|
53
52
|
else
|
54
53
|
next
|
55
54
|
end
|
56
|
-
@plans <<
|
55
|
+
@plans << plan_class.new(elems[:datetime ],
|
56
|
+
elems[:flag_time ],
|
57
|
+
elems[:option ],
|
58
|
+
elems[:description],
|
59
|
+
)
|
57
60
|
rescue Sculd::Plan::WeekdayMismatchError
|
58
|
-
io.puts "error occured at #{index}: #{line}"
|
61
|
+
io.puts "error occured at #{index}: #{line.to_i + 1}"
|
59
62
|
raise LoadError
|
63
|
+
rescue Sculd::Plan::NotNumberError
|
64
|
+
#io.puts "error occured at #{index}: #{line+1}"
|
65
|
+
#raise LoadError
|
66
|
+
next
|
60
67
|
rescue
|
61
68
|
# do nothing
|
62
69
|
end
|
@@ -89,11 +96,28 @@ class Sculd::Manager
|
|
89
96
|
#HIGHLINE.say(" <%= color(#{date.to_s} #{WEEKDAYS[date.wday]}, :white, :red) %>")
|
90
97
|
#hl.say(" <%= color('red', :red) %>!")
|
91
98
|
#io.puts str
|
92
|
-
events.sort_by{|i| i.datetime}.each do |
|
93
|
-
|
99
|
+
events.sort_by{|i| i.datetime}.each do |event|
|
100
|
+
#pp event
|
101
|
+
|
102
|
+
io.print(" ") #indent
|
103
|
+
event_date = Date.new(event.datetime.year,
|
104
|
+
event.datetime.month,
|
105
|
+
event.datetime.day)
|
106
|
+
if event_date != date
|
107
|
+
io.printf("<%02d/%02d>", event.datetime.month, event.datetime.day )
|
108
|
+
elsif event.flag_time
|
109
|
+
io.printf("[%02d:%02d]", event.datetime.hour, event.datetime.minute )
|
110
|
+
else
|
111
|
+
io.print(" ")
|
112
|
+
end
|
113
|
+
io.printf("%s", event.class::SYMBOL_CHAR )
|
114
|
+
io.printf("%-2s ", event.option.to_s )
|
115
|
+
io.puts "#{event.description}"
|
116
|
+
|
117
|
+
#io.puts " #{event.description.strip}"
|
94
118
|
end
|
95
119
|
else
|
96
|
-
io.puts " (no
|
120
|
+
io.puts " (no event)"
|
97
121
|
end
|
98
122
|
io.puts
|
99
123
|
end
|
@@ -104,10 +128,12 @@ class Sculd::Manager
|
|
104
128
|
def days_events
|
105
129
|
results = {}
|
106
130
|
@plans.each do |plan|
|
107
|
-
|
108
|
-
|
131
|
+
#puts
|
132
|
+
#p plan
|
133
|
+
plan.event_dates.each do |date|
|
134
|
+
#pp date
|
109
135
|
results[date] ||= []
|
110
|
-
results[date] <<
|
136
|
+
results[date] << plan
|
111
137
|
end
|
112
138
|
end
|
113
139
|
return results
|
@@ -119,11 +145,21 @@ class Sculd::Manager
|
|
119
145
|
|
120
146
|
io.puts "Tasks:"
|
121
147
|
plans = @plans.sort_by {|plan| plan.priority(today)}.reverse
|
122
|
-
#pp plans
|
123
148
|
|
124
149
|
num = plans.size if plans.size < num
|
125
150
|
plans[0..(num-1)].each do |plan|
|
126
|
-
io.
|
151
|
+
io.printf(" [%4d-%02d-%02d]",
|
152
|
+
plan.datetime.year,
|
153
|
+
plan.datetime.month,
|
154
|
+
plan.datetime.day,
|
155
|
+
)
|
156
|
+
io.printf("%s%-2s %s",
|
157
|
+
plan.class::SYMBOL_CHAR,
|
158
|
+
plan.option.to_s,
|
159
|
+
plan.description
|
160
|
+
#io.print " #{plan.description.strip}"
|
161
|
+
)
|
162
|
+
io.puts
|
127
163
|
end
|
128
164
|
end
|
129
165
|
end
|
data/lib/sculd/plan.rb
CHANGED
@@ -13,8 +13,9 @@ class Sculd::Plan
|
|
13
13
|
class NotDefinedError < Exception; end
|
14
14
|
class WeekdayMismatchError < Exception; end
|
15
15
|
class NotWeekdayError < Exception; end
|
16
|
+
class NotNumberError < Exception; end
|
16
17
|
|
17
|
-
attr_reader :description
|
18
|
+
attr_reader :description, :flag_time, :datetime, :option
|
18
19
|
|
19
20
|
REMINDER_PRIORITY = 10000
|
20
21
|
DEADLINE_PRIORITY = 20000
|
@@ -22,27 +23,33 @@ class Sculd::Plan
|
|
22
23
|
# Parse and return date, type, option.
|
23
24
|
def self.parse(str, io = $stdout)
|
24
25
|
#/\[([\d\- :]*)\](.)(\S*)/ =~ str #OK
|
25
|
-
/\[([^\]]*)\](.)(\S*)/ =~ str #OK
|
26
|
+
/\[([^\]]*)\](.)(\S*)\s+(.*)/ =~ str #OK
|
27
|
+
result = {}
|
26
28
|
|
27
|
-
|
28
|
-
type = $2
|
29
|
-
option = $3.to_s
|
29
|
+
date, type, option, description = $1, $2, $3, $4
|
30
30
|
|
31
|
-
datetime = DateTime::parse
|
32
|
-
if /\((.+)\)/ =~
|
33
|
-
#pp $1
|
34
|
-
#pp datetime.wday
|
35
|
-
#pp self.wday($1)
|
31
|
+
datetime = DateTime::parse date
|
32
|
+
if /\((.+)\)/ =~ date
|
36
33
|
unless self.wday($1) == datetime.wday
|
37
|
-
#io.puts "#{datetime} is #{Sculd::Manager::WEEKDAYS[datetime.wday]},"
|
38
|
-
#io.puts "but string contains #{datestr}."
|
39
34
|
io.puts "ERROR:"
|
40
35
|
io.puts "#{datetime} is #{Sculd::Manager::WEEKDAYS[datetime.wday]},"
|
41
|
-
io.puts "but string contains #{
|
36
|
+
io.puts "but string contains #{date}."
|
42
37
|
raise WeekdayMismatchError
|
43
38
|
end
|
44
39
|
end
|
45
|
-
|
40
|
+
result[:datetime] = datetime
|
41
|
+
result[:flag_time] = date.include?(":")
|
42
|
+
|
43
|
+
result[:type] = type
|
44
|
+
|
45
|
+
unless option.empty?
|
46
|
+
raise NotNumberError unless option =~ /^[0-9]+$/
|
47
|
+
result[:option] = option.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
result[:description] = description
|
51
|
+
|
52
|
+
return result
|
46
53
|
end
|
47
54
|
|
48
55
|
def self.wday(str)
|
@@ -67,9 +74,10 @@ class Sculd::Plan
|
|
67
74
|
end
|
68
75
|
|
69
76
|
#
|
70
|
-
def initialize(datetime, option, description)
|
71
|
-
@datetime
|
72
|
-
@
|
77
|
+
def initialize(datetime, flag_time, option, description)
|
78
|
+
@datetime = datetime
|
79
|
+
@flag_time = flag_time
|
80
|
+
@option = option
|
73
81
|
@description = description
|
74
82
|
end
|
75
83
|
|
@@ -78,7 +86,7 @@ class Sculd::Plan
|
|
78
86
|
raise NotDefinedError
|
79
87
|
end
|
80
88
|
|
81
|
-
def
|
89
|
+
def event_dates
|
82
90
|
raise NotDefinedError
|
83
91
|
end
|
84
92
|
end
|
data/lib/sculd/plan/deadline.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
3
|
|
4
|
-
require "sculd/event.rb"
|
5
|
-
require "sculd/plan.rb"
|
4
|
+
#require "sculd/event.rb"
|
5
|
+
#require "sculd/plan.rb"
|
6
6
|
|
7
7
|
#
|
8
8
|
#
|
9
9
|
#
|
10
10
|
class Sculd::Plan::Deadline < Sculd::Plan
|
11
11
|
|
12
|
+
SYMBOL_CHAR = "!"
|
13
|
+
DEFAULT_OPTION = 7
|
14
|
+
|
12
15
|
def priority(today)
|
13
|
-
|
14
|
-
beginning = @datetime - @option
|
16
|
+
#@option = 1 if @option < 1
|
17
|
+
beginning = @datetime - (@option || DEFAULT_OPTION)
|
15
18
|
if today < beginning
|
16
19
|
return 0
|
17
20
|
elsif today <= @datetime
|
@@ -23,11 +26,15 @@ class Sculd::Plan::Deadline < Sculd::Plan
|
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
26
|
-
def
|
29
|
+
def event_dates
|
30
|
+
#@option ||= DEFAULT_OPTION
|
31
|
+
|
27
32
|
results = []
|
28
|
-
results <<
|
29
|
-
results <<
|
30
|
-
|
33
|
+
results << @datetime - (@option || DEFAULT_OPTION)
|
34
|
+
results << @datetime
|
35
|
+
results.map do |datetime|
|
36
|
+
Date.new(datetime.year, datetime.month, datetime.day)
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
33
40
|
|
data/lib/sculd/plan/reminder.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
3
|
|
4
|
-
require "sculd/event.rb"
|
5
|
-
require "sculd/plan.rb"
|
4
|
+
#require "sculd/event.rb"
|
5
|
+
#require "sculd/plan.rb"
|
6
6
|
|
7
7
|
#
|
8
8
|
#
|
9
9
|
#
|
10
10
|
class Sculd::Plan::Reminder < Sculd::Plan
|
11
|
+
|
12
|
+
SYMBOL_CHAR = "-"
|
13
|
+
|
11
14
|
# value of @option does not work
|
12
15
|
def priority(today = Date.now)
|
13
16
|
if today < @datetime
|
@@ -18,8 +21,8 @@ class Sculd::Plan::Reminder < Sculd::Plan
|
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
21
|
-
def
|
22
|
-
|
24
|
+
def event_dates
|
25
|
+
[Date.new(@datetime.year, @datetime.month, @datetime.day)]
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
data/lib/sculd/plan/schedule.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
3
|
|
4
|
-
require "sculd/event.rb"
|
4
|
+
#require "sculd/event.rb"
|
5
5
|
|
6
6
|
#
|
7
7
|
#
|
8
8
|
#
|
9
9
|
class Sculd::Plan::Schedule < Sculd::Plan
|
10
|
+
|
11
|
+
SYMBOL_CHAR = "@"
|
12
|
+
|
10
13
|
#
|
11
14
|
def priority(today = Date.new)
|
12
15
|
return 0
|
13
16
|
end
|
14
17
|
|
15
|
-
def
|
16
|
-
|
18
|
+
def event_dates
|
19
|
+
[Date.new(@datetime.year, @datetime.month, @datetime.day)]
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|