sculd 0.1.3 → 0.2.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.
- checksums.yaml +7 -0
- data/CHANGES +15 -2
- data/Gemfile +6 -8
- data/VERSION +1 -1
- data/bin/dates +0 -1
- data/bin/sculd +76 -31
- data/lib/sculd/manager.rb +142 -141
- data/lib/sculd/plan.rb +72 -78
- data/lib/sculd/plan/deadline.rb +27 -27
- data/lib/sculd/plan/reminder.rb +12 -12
- data/lib/sculd/plan/schedule.rb +8 -8
- data/lib/sculd/plan/todo.rb +25 -25
- data/sculd.gemspec +24 -20
- data/test/helper.rb +4 -4
- data/test/test_deadline.rb +47 -47
- data/test/test_manager.rb +108 -98
- data/test/test_plan.rb +96 -88
- data/test/test_reminder.rb +28 -28
- data/test/test_schedule.rb +17 -17
- data/test/test_todo.rb +40 -40
- metadata +44 -45
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e5f8afdf363dced7623854381b2ebf40ae7c20d
|
4
|
+
data.tar.gz: a94f0df0b433e2120eb1e72667d0e1ddc6988e96
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb494f786bf70a17014f78d637618b893743f5dfc0161c1c6832f1a615300316e9de0c2fae1e48c040ca44502d33245614dcd63bf93802faeb62cdfaa4466b30
|
7
|
+
data.tar.gz: d84fd258f5e34948d215a775aedf9ad7a8aecb5b964d22ac57ff138925c88c08644bb3ea78a0360a94d36d6f1b1600b83143a8745fe8a4d6606aed7da327bcd3
|
data/CHANGES
CHANGED
@@ -1,38 +1,51 @@
|
|
1
1
|
= sdrt changelog
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
== Version 0.2.0 [2017-04-24] released
|
4
|
+
|
5
|
+
* Change command line specification. Get arguments as list of dates.
|
6
|
+
* Change the role of ~/.sculd; from directory to configuration file.
|
7
|
+
* Enable use local name for weekdays to show events.
|
8
|
+
* Enable use Japanese weekday names for reminder writing.
|
9
|
+
* Add --weekday option
|
5
10
|
|
6
11
|
== Version 0.1.3 [2014-08-29] released
|
12
|
+
|
7
13
|
* Bugfix to show only one event when deadline with option 0, like [2013-12-10]!0 .
|
8
14
|
* Bugfix to generate NaN when deadline with option 0, like [2013-12-10]!0 on the day.
|
9
15
|
|
10
16
|
== Version 0.1.2 [2014-05-06] released
|
17
|
+
|
11
18
|
* Adjust to highline-1.6.21.
|
12
19
|
|
13
20
|
== Version 0.1.1 [2013-05-21] released
|
21
|
+
|
14
22
|
* Bugfix of show_task.
|
15
23
|
|
16
24
|
== Version 0.1.0 [2013-05-17] released
|
25
|
+
|
17
26
|
* Use test-unit alternatively to rspec.
|
18
27
|
* Enable to use directory, ~/.sculd alternatively to ~/.sculd.dat
|
19
28
|
* Change output format.
|
20
29
|
* Change library interfaces.
|
21
30
|
|
22
31
|
== Version 0.0.3 [2013-04-18] released
|
32
|
+
|
23
33
|
* Options -s, -t, -i is made into bin/dates command.
|
24
34
|
* Use /usr/bin/env ruby in bin/dates, alternatively to /usr/bin/ruby.
|
25
35
|
|
26
36
|
== Version 0.0.2 [2012-11-19] released
|
37
|
+
|
27
38
|
* Dates are changed to be shown in colors.
|
28
39
|
* Dates which has no plan shows '(no plan)'
|
29
40
|
|
30
41
|
== Version 0.0.1
|
42
|
+
|
31
43
|
* Enable to use date and time.
|
32
44
|
* Plan.parse is modified to deal with time.
|
33
45
|
* [datetime(wday)], date and weekday, style is introduced, to check correct date.
|
34
46
|
* Add dates command to help you input your plans.
|
35
47
|
|
36
48
|
== Version 0.0.0
|
49
|
+
|
37
50
|
* Initial release.
|
38
51
|
|
data/Gemfile
CHANGED
@@ -6,12 +6,10 @@ 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
|
-
|
10
|
-
|
11
|
-
gem "
|
12
|
-
gem "
|
13
|
-
gem "
|
14
|
-
gem "
|
15
|
-
gem "highline", ">= 1.6.21"
|
16
|
-
#gem "psych", ">= 0"
|
9
|
+
gem "test-unit", "~> 3.2"
|
10
|
+
gem "rdoc", "~> 4.2"
|
11
|
+
gem "bundler", "~> 1.11"
|
12
|
+
gem "jeweler", "~> 2.0"
|
13
|
+
gem "simplecov", "~> 0.11"
|
14
|
+
gem "highline", "~> 1.6"
|
17
15
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/dates
CHANGED
data/bin/sculd
CHANGED
@@ -5,56 +5,101 @@
|
|
5
5
|
# Events include schedule and deadline(start and end).
|
6
6
|
# Tasks include deadline, reminder and todo.
|
7
7
|
|
8
|
-
|
9
|
-
SCULD_DIR = "#{ENV['HOME']}/.sculd"
|
8
|
+
SCULD_CONF = "#{ENV['HOME']}/.sculd"
|
10
9
|
|
11
10
|
require "pp"
|
12
11
|
require "optparse"
|
13
|
-
require "rubygems"
|
14
|
-
gem "sculd"
|
15
12
|
require "sculd"
|
13
|
+
require "yaml"
|
16
14
|
|
17
15
|
# option analysis
|
18
|
-
|
16
|
+
OPTIONS = {}
|
19
17
|
op = OptionParser.new
|
20
|
-
op.on("-
|
21
|
-
|
22
|
-
|
18
|
+
op.on("-a day", "--after days" , "Event after n days."){|v|
|
19
|
+
OPTIONS[:after] = v.to_i}
|
20
|
+
op.on("-b day", "--before days", "Event before n days."){|v|
|
21
|
+
OPTIONS[:before] = v.to_i}
|
22
|
+
op.on("-c day", "--center days", "Event days between n days."){|v|
|
23
|
+
OPTIONS[:center] = v.to_i}
|
24
|
+
op.on("-w weekdays", "--weekdays=wdays", "Event days only on weekdays. E.g., --weekday='Sun,Mon'"){|v|
|
25
|
+
OPTIONS[:weekdays] = v.split ','}
|
26
|
+
op.on("-t num", "--task num" , "Show tasks on today." ){|v|
|
27
|
+
OPTIONS[:task ] = v.to_i}
|
23
28
|
op.parse!(ARGV)
|
24
29
|
|
25
|
-
#num_day = ARGV.shift.to_i
|
26
|
-
#num_task = ARGV.shift.to_i
|
27
|
-
OPTS[:event] ||= 0
|
28
|
-
OPTS[:task ] ||= 0
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
## ~/.sculd check
|
32
|
+
begin
|
33
|
+
configurations = YAML.load_file SCULD_CONF
|
34
|
+
rescue
|
35
|
+
puts "'sculd' command requires ~/.sculd file with YAML format; not directory."
|
36
|
+
puts "key as sculd_dir and value as the path to directory should be indicated in ~/.sculd."
|
32
37
|
exit
|
33
38
|
end
|
39
|
+
sculd_dir = configurations['sculd_dir']
|
40
|
+
|
41
|
+
## dates
|
42
|
+
if ARGV.empty?
|
43
|
+
dates = [Date.today]
|
44
|
+
else
|
45
|
+
dates = []
|
46
|
+
ARGV.each do |v|
|
47
|
+
begin
|
48
|
+
date = (Date.parse v)
|
49
|
+
rescue ArgumentError
|
50
|
+
next
|
51
|
+
end
|
52
|
+
dates << date
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if OPTIONS[:center]
|
57
|
+
OPTIONS[:after] ||= OPTIONS[:center]
|
58
|
+
OPTIONS[:before] ||= OPTIONS[:center]
|
59
|
+
end
|
60
|
+
|
61
|
+
if OPTIONS[:after]
|
62
|
+
results = []
|
63
|
+
dates.each do |date|
|
64
|
+
0.upto OPTIONS[:after] do |i|
|
65
|
+
results << date + i
|
66
|
+
end
|
67
|
+
end
|
68
|
+
dates = results
|
69
|
+
end
|
70
|
+
|
71
|
+
if OPTIONS[:before]
|
72
|
+
results = []
|
73
|
+
dates.each do |date|
|
74
|
+
0.upto OPTIONS[:before] do |i|
|
75
|
+
results << date - i
|
76
|
+
end
|
77
|
+
end
|
78
|
+
dates = results
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
if OPTIONS[:weekdays]
|
83
|
+
weekdays = OPTIONS[:weekdays].map {|v| Sculd::Plan.wday v}
|
84
|
+
dates.select!{|date| weekdays.include? date.wday}
|
85
|
+
end
|
86
|
+
#pp dates
|
34
87
|
|
35
|
-
|
36
|
-
#file ||= SCULD_DAT
|
88
|
+
dates = dates.sort.uniq
|
37
89
|
|
38
|
-
unless FileTest.exist?
|
39
|
-
|
40
|
-
#rescue
|
41
|
-
puts "Not found #{SCULD_DIR}. Exit."
|
90
|
+
unless FileTest.exist? sculd_dir
|
91
|
+
puts "Not found #{sculd_dir}. Exit."
|
42
92
|
exit
|
43
93
|
end
|
44
94
|
|
45
95
|
begin
|
46
|
-
sm = Sculd::Manager.new(
|
47
|
-
|
96
|
+
sm = Sculd::Manager.new(sculd_dir)
|
97
|
+
sm.set_weekdays configurations['weekdays'] if configurations['weekdays']
|
98
|
+
rescue Sculd::Manager::LoadError => message
|
99
|
+
puts message
|
48
100
|
puts "Exit."
|
49
101
|
exit
|
50
102
|
end
|
51
|
-
|
52
|
-
sm.
|
103
|
+
sm.show_events(dates)
|
104
|
+
sm.show_tasks(OPTIONS[:task ]) if OPTIONS[:task]
|
53
105
|
|
54
|
-
#while (true)
|
55
|
-
# s.show(OPTS[:event], OPTS[:task])
|
56
|
-
# command = STDIN.gets
|
57
|
-
# case
|
58
|
-
# when command ==
|
59
|
-
# end
|
60
|
-
#end
|
data/lib/sculd/manager.rb
CHANGED
@@ -2,165 +2,166 @@
|
|
2
2
|
# coding: utf-8
|
3
3
|
|
4
4
|
require "date"
|
5
|
-
require "sculd.rb"
|
6
5
|
|
7
6
|
require "rubygems"
|
8
|
-
#gem "highline"
|
9
7
|
require "highline"
|
10
8
|
|
11
9
|
#
|
12
10
|
#
|
13
11
|
#
|
14
12
|
class Sculd::Manager
|
15
|
-
|
16
|
-
WEEKDAYS = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
|
13
|
+
attr_reader :weekdays
|
17
14
|
|
18
|
-
|
15
|
+
DEFAULT_WEEKDAYS = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
@source_dir = dir
|
23
|
-
@plans = []
|
24
|
-
Dir.glob("#{@source_dir}/*").each do |file|
|
25
|
-
load_file(file, io)
|
26
|
-
end
|
27
|
-
end
|
17
|
+
class LoadError < StandardError; end
|
18
|
+
class ArgumentError < StandardError; end
|
28
19
|
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
def initialize(dir, io = $stdout)
|
21
|
+
@source_dir = dir
|
22
|
+
@weekdays = DEFAULT_WEEKDAYS
|
23
|
+
@plans = []
|
24
|
+
Dir.glob("#{@source_dir}/*").each do |file|
|
25
|
+
load_file(file, io)
|
32
26
|
end
|
27
|
+
end
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def load_file(file, io = $stdio)
|
38
|
-
|
39
|
-
File.open(file, "r").readlines.each_with_index do |line, index|
|
40
|
-
begin
|
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
|
52
|
-
else
|
53
|
-
next
|
54
|
-
end
|
55
|
-
@plans << plan_class.new(elems[:datetime ],
|
56
|
-
elems[:flag_time ],
|
57
|
-
elems[:option ],
|
58
|
-
elems[:description],
|
59
|
-
)
|
60
|
-
rescue Sculd::Plan::WeekdayMismatchError
|
61
|
-
io.puts "error occured at #{index}: #{line.to_i + 1}"
|
62
|
-
raise LoadError
|
63
|
-
rescue Sculd::Plan::NotNumberError
|
64
|
-
#io.puts "error occured at #{index}: #{line+1}"
|
65
|
-
#raise LoadError
|
66
|
-
next
|
67
|
-
rescue
|
68
|
-
# do nothing
|
69
|
-
end
|
70
|
-
end
|
29
|
+
def set_weekdays(ary)
|
30
|
+
unless ary.size == 7
|
31
|
+
raise ArgumentError, ary.to_s
|
71
32
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
else
|
120
|
-
io.puts " (no event)"
|
121
|
-
end
|
122
|
-
io.puts
|
33
|
+
@weekdays = ary
|
34
|
+
end
|
35
|
+
|
36
|
+
#def show(num_event, num_task, io = $stdout)
|
37
|
+
# show_events(num_event)
|
38
|
+
# show_tasks(num_task)
|
39
|
+
#end
|
40
|
+
|
41
|
+
# Show events in 'num' days from todary.
|
42
|
+
#def show_events(num, today = Date.today, io = $stdout)
|
43
|
+
def show_events(dates, io = $stdout)
|
44
|
+
hl = HighLine.new($stdin, io)
|
45
|
+
|
46
|
+
d_e = days_events
|
47
|
+
io.puts "Events:"
|
48
|
+
dates.each do |date|
|
49
|
+
str = " #{date.to_s} #{@weekdays[date.wday]} "
|
50
|
+
|
51
|
+
case date.wday
|
52
|
+
when 0
|
53
|
+
fgcolor = ":white"; bgcolor = ":on_red";
|
54
|
+
when 6
|
55
|
+
fgcolor = ":white"; bgcolor = ":on_blue";
|
56
|
+
else
|
57
|
+
fgcolor = ":black"; bgcolor = ":on_white";
|
58
|
+
end
|
59
|
+
hl.say(" <%= color('#{str}', #{fgcolor}, #{bgcolor}) %>\n")
|
60
|
+
|
61
|
+
events = d_e[date]
|
62
|
+
if events # if plan is not empty.
|
63
|
+
events.sort_by{|j| j.datetime}.each do |event|
|
64
|
+
|
65
|
+
io.print(" ") #indent
|
66
|
+
event_date = Date.new(event.datetime.year,
|
67
|
+
event.datetime.month,
|
68
|
+
event.datetime.day)
|
69
|
+
if event_date != date
|
70
|
+
io.printf("<%02d/%02d>", event.datetime.month, event.datetime.day )
|
71
|
+
elsif event.flag_time
|
72
|
+
io.printf("[%02d:%02d]", event.datetime.hour, event.datetime.minute )
|
73
|
+
else
|
74
|
+
io.print(" ")
|
75
|
+
end
|
76
|
+
io.printf("%s", event.class::SYMBOL_CHAR )
|
77
|
+
io.printf("%-2s ", event.option.to_s )
|
78
|
+
io.puts "#{event.description}"
|
123
79
|
end
|
80
|
+
else
|
81
|
+
io.puts " (no event)"
|
82
|
+
end
|
83
|
+
io.puts
|
124
84
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
85
|
+
end
|
86
|
+
|
87
|
+
# Show 'num' tasks of the highest priority.
|
88
|
+
def show_tasks(num, today = Date.today, io = $stdout)
|
89
|
+
return if num == 0
|
90
|
+
|
91
|
+
io.puts "Tasks:"
|
92
|
+
plans = @plans.sort_by {|plan| plan.priority(today)}.reverse
|
93
|
+
|
94
|
+
num = plans.size if plans.size < num
|
95
|
+
plans[0..(num-1)].each do |plan|
|
96
|
+
io.printf(" [%4d-%02d-%02d]",
|
97
|
+
plan.datetime.year,
|
98
|
+
plan.datetime.month,
|
99
|
+
plan.datetime.day,
|
100
|
+
)
|
101
|
+
io.printf("%s%-2s %s",
|
102
|
+
plan.class::SYMBOL_CHAR,
|
103
|
+
plan.option.to_s,
|
104
|
+
plan.description
|
105
|
+
#io.print " #{plan.description.strip}"
|
106
|
+
)
|
107
|
+
io.puts
|
140
108
|
end
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
io.puts
|
109
|
+
end
|
110
|
+
private
|
111
|
+
|
112
|
+
# read, parse file and set data to @events and @tasks.
|
113
|
+
def load_file(file, io = $stdin)
|
114
|
+
|
115
|
+
File.open(file, "r").readlines.each_with_index do |line, index|
|
116
|
+
begin
|
117
|
+
elems = Sculd::Plan.parse(line, io)
|
118
|
+
next unless elems[:type]
|
119
|
+
case elems[:type]
|
120
|
+
when Sculd::Plan::Schedule::SYMBOL_CHAR
|
121
|
+
plan_class = Sculd::Plan::Schedule
|
122
|
+
when Sculd::Plan::Deadline::SYMBOL_CHAR
|
123
|
+
plan_class = Sculd::Plan::Deadline
|
124
|
+
when Sculd::Plan::Reminder::SYMBOL_CHAR
|
125
|
+
plan_class = Sculd::Plan::Reminder
|
126
|
+
when Sculd::Plan::Todo::SYMBOL_CHAR
|
127
|
+
plan_class = Sculd::Plan::Todo
|
128
|
+
else
|
129
|
+
next
|
163
130
|
end
|
131
|
+
@plans << plan_class.new(elems[:datetime ],
|
132
|
+
elems[:flag_time ],
|
133
|
+
elems[:option ],
|
134
|
+
elems[:description],
|
135
|
+
)
|
136
|
+
rescue Sculd::Plan::WeekdayMismatchError => error
|
137
|
+
message = error.message
|
138
|
+
message += "\nError occured in #{file} at #{index}: #{line.to_i + 1}\n"
|
139
|
+
message += line
|
140
|
+
raise LoadError, message
|
141
|
+
rescue Sculd::Plan::NotWeekdayError => error
|
142
|
+
message = error.message
|
143
|
+
message += "\nError occured in #{file} at #{index}: #{line.to_i + 1}\n"
|
144
|
+
message += line
|
145
|
+
raise LoadError, message
|
146
|
+
rescue Sculd::Plan::NotNumberError
|
147
|
+
next
|
148
|
+
rescue
|
149
|
+
end
|
164
150
|
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# Return a hash of dates and events.
|
154
|
+
# The eventes generated from @schedules sorted by date and time.
|
155
|
+
def days_events
|
156
|
+
results = {}
|
157
|
+
@plans.each do |plan|
|
158
|
+
plan.event_dates.each do |date|
|
159
|
+
results[date] ||= []
|
160
|
+
results[date] << plan
|
161
|
+
end
|
162
|
+
end
|
163
|
+
return results
|
164
|
+
end
|
165
|
+
|
165
166
|
end
|
166
167
|
|