sculd 0.1.2 → 0.1.3
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 +4 -2
- data/Gemfile +1 -2
- data/VERSION +1 -1
- data/lib/sculd/manager.rb +142 -142
- data/lib/sculd/plan.rb +73 -73
- data/lib/sculd/plan/deadline.rb +27 -25
- 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 +5 -5
- data/test/helper.rb +4 -4
- data/test/test_deadline.rb +49 -45
- data/test/test_manager.rb +94 -94
- data/test/test_plan.rb +88 -88
- data/test/test_reminder.rb +28 -28
- data/test/test_schedule.rb +17 -17
- data/test/test_todo.rb +40 -40
- metadata +5 -5
data/CHANGES
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
= sdrt changelog
|
2
2
|
|
3
3
|
TODO
|
4
|
-
* Bugfix to show only one event when [2013-12-10]!0 .
|
5
|
-
|
6
4
|
== Master
|
7
5
|
|
6
|
+
== Version 0.1.3 [2014-08-29] released
|
7
|
+
* Bugfix to show only one event when deadline with option 0, like [2013-12-10]!0 .
|
8
|
+
* Bugfix to generate NaN when deadline with option 0, like [2013-12-10]!0 on the day.
|
9
|
+
|
8
10
|
== Version 0.1.2 [2014-05-06] released
|
9
11
|
* Adjust to highline-1.6.21.
|
10
12
|
|
data/Gemfile
CHANGED
@@ -7,10 +7,9 @@ source "http://rubygems.org"
|
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
9
|
#gem "rdoc", "~> 4.0.1"
|
10
|
-
#gem "jeweler", "~> 1.8.4"
|
11
10
|
#gem "simplecov", ">= 0"
|
12
11
|
gem "rdoc", "~> 4.1.1"
|
13
|
-
gem "bundler", "~> 1.
|
12
|
+
gem "bundler", "~> 1.7.2"
|
14
13
|
gem "jeweler", "~> 2.0.1"
|
15
14
|
gem "simplecov", ">= 0.8.2"
|
16
15
|
gem "highline", ">= 1.6.21"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/sculd/manager.rb
CHANGED
@@ -5,162 +5,162 @@ require "date"
|
|
5
5
|
require "sculd.rb"
|
6
6
|
|
7
7
|
require "rubygems"
|
8
|
-
#gem
|
8
|
+
#gem "highline"
|
9
9
|
require "highline"
|
10
10
|
|
11
11
|
#
|
12
12
|
#
|
13
13
|
#
|
14
14
|
class Sculd::Manager
|
15
|
-
|
16
|
-
|
15
|
+
#WEEKDAYS = [ "日", "月", "火", "水", "木", "金", "土" ]
|
16
|
+
WEEKDAYS = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
|
17
17
|
|
18
|
-
|
18
|
+
class LoadError < Exception; end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
#
|
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
|
27
|
+
end
|
28
|
+
|
29
|
+
def show(num_event, num_task, io = $stdout)
|
30
|
+
show_events(num_event)
|
31
|
+
show_tasks(num_task)
|
26
32
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# read, parse file and set data to @events and @tasks.
|
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
|
54
70
|
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
71
|
end
|
71
|
-
|
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
|
-
|
72
|
+
|
73
|
+
# Show events in 'num' days from todary.
|
74
|
+
def show_events(num, today = Date.today, io = $stdout)
|
75
|
+
return if num == 0
|
76
|
+
hl = HighLine.new($stdin, io)
|
77
|
+
|
78
|
+
d_e = days_events
|
79
|
+
io.puts "Events:"
|
80
|
+
num.times do |i|
|
81
|
+
date = today + i
|
82
|
+
str = " #{date.to_s} #{WEEKDAYS[date.wday]} "
|
83
|
+
|
84
|
+
case date.wday
|
85
|
+
when 0
|
86
|
+
hl.say(" <%= color('#{str}', :white, :on_red) %>\n")
|
87
|
+
when 6
|
88
|
+
hl.say(" <%= color('#{str}', :white, :on_blue) %>\n")
|
89
|
+
else
|
90
|
+
hl.say(" <%= color('#{str}', :white, :on_black) %>\n")
|
91
|
+
end
|
92
|
+
|
93
|
+
events = d_e[date]
|
94
|
+
if events # if plan is not empty.
|
95
|
+
#HIGHLINE.say("<%= color('red', :red) %>!")
|
96
|
+
#HIGHLINE.say(" <%= color(#{date.to_s} #{WEEKDAYS[date.wday]}, :white, :red) %>")
|
97
|
+
#hl.say(" <%= color('red', :red) %>!")
|
98
|
+
#io.puts str
|
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}"
|
118
|
+
end
|
119
|
+
else
|
120
|
+
io.puts " (no event)"
|
121
|
+
end
|
122
|
+
io.puts
|
118
123
|
end
|
119
|
-
else
|
120
|
-
io.puts " (no event)"
|
121
|
-
end
|
122
|
-
io.puts
|
123
124
|
end
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
125
|
+
|
126
|
+
# Return a hash of dates and events.
|
127
|
+
# The eventes generated from @schedules sorted by date and time.
|
128
|
+
def days_events
|
129
|
+
results = {}
|
130
|
+
@plans.each do |plan|
|
131
|
+
#puts
|
132
|
+
#p plan
|
133
|
+
plan.event_dates.each do |date|
|
134
|
+
#pp date
|
135
|
+
results[date] ||= []
|
136
|
+
results[date] << plan
|
137
|
+
end
|
138
|
+
end
|
139
|
+
return results
|
138
140
|
end
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
io.puts
|
141
|
+
|
142
|
+
# Show 'num' tasks of the highest priority.
|
143
|
+
def show_tasks(num, today = Date.today, io = $stdout)
|
144
|
+
return if num == 0
|
145
|
+
|
146
|
+
io.puts "Tasks:"
|
147
|
+
plans = @plans.sort_by {|plan| plan.priority(today)}.reverse
|
148
|
+
|
149
|
+
num = plans.size if plans.size < num
|
150
|
+
plans[0..(num-1)].each do |plan|
|
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
|
163
|
+
end
|
163
164
|
end
|
164
|
-
end
|
165
165
|
end
|
166
166
|
|
data/lib/sculd/plan.rb
CHANGED
@@ -10,84 +10,84 @@
|
|
10
10
|
#
|
11
11
|
#
|
12
12
|
class Sculd::Plan
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
13
|
+
class NotDefinedError < Exception; end
|
14
|
+
class WeekdayMismatchError < Exception; end
|
15
|
+
class NotWeekdayError < Exception; end
|
16
|
+
class NotNumberError < Exception; end
|
17
|
+
|
18
|
+
attr_reader :description, :flag_time, :datetime, :option
|
19
|
+
|
20
|
+
REMINDER_PRIORITY = 10000
|
21
|
+
DEADLINE_PRIORITY = 20000
|
22
|
+
|
23
|
+
# Parse and return date, type, option.
|
24
|
+
def self.parse(str, io = $stdout)
|
25
|
+
#/\[([\d\- :]*)\](.)(\S*)/ =~ str #OK
|
26
|
+
/\[([^\]]*)\](.)(\S*)\s+(.*)/ =~ str #OK
|
27
|
+
result = {}
|
28
|
+
|
29
|
+
date, type, option, description = $1, $2, $3, $4
|
30
|
+
|
31
|
+
datetime = DateTime::parse date
|
32
|
+
if /\((.+)\)/ =~ date
|
33
|
+
unless self.wday($1) == datetime.wday
|
34
|
+
io.puts "ERROR:"
|
35
|
+
io.puts "#{datetime} is #{Sculd::Manager::WEEKDAYS[datetime.wday]},"
|
36
|
+
io.puts "but string contains #{date}."
|
37
|
+
raise WeekdayMismatchError
|
38
|
+
end
|
39
|
+
end
|
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
|
39
53
|
end
|
40
|
-
result[:datetime] = datetime
|
41
|
-
result[:flag_time] = date.include?(":")
|
42
54
|
|
43
|
-
|
55
|
+
def self.wday(str)
|
56
|
+
case str
|
57
|
+
when /^Su/i
|
58
|
+
return 0
|
59
|
+
when /^M/i
|
60
|
+
return 1
|
61
|
+
when /^Tu/i
|
62
|
+
return 2
|
63
|
+
when /^W/i
|
64
|
+
return 3
|
65
|
+
when /^Th/i
|
66
|
+
return 4
|
67
|
+
when /^F/i
|
68
|
+
return 5
|
69
|
+
when /^Sa/i
|
70
|
+
return 6
|
71
|
+
else
|
72
|
+
raise NotWeekdayError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
def initialize(datetime, flag_time, option, description)
|
78
|
+
@datetime = datetime
|
79
|
+
@flag_time = flag_time
|
80
|
+
@option = option
|
81
|
+
@description = description
|
82
|
+
end
|
44
83
|
|
45
|
-
|
46
|
-
|
47
|
-
|
84
|
+
# return priority of task calculated by equation defined in subclass.
|
85
|
+
def priority
|
86
|
+
raise NotDefinedError
|
48
87
|
end
|
49
88
|
|
50
|
-
|
51
|
-
|
52
|
-
return result
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.wday(str)
|
56
|
-
case str
|
57
|
-
when /^Su/i
|
58
|
-
return 0
|
59
|
-
when /^M/i
|
60
|
-
return 1
|
61
|
-
when /^Tu/i
|
62
|
-
return 2
|
63
|
-
when /^W/i
|
64
|
-
return 3
|
65
|
-
when /^Th/i
|
66
|
-
return 4
|
67
|
-
when /^F/i
|
68
|
-
return 5
|
69
|
-
when /^Sa/i
|
70
|
-
return 6
|
71
|
-
else
|
72
|
-
raise NotWeekdayError
|
89
|
+
def event_dates
|
90
|
+
raise NotDefinedError
|
73
91
|
end
|
74
|
-
end
|
75
|
-
|
76
|
-
#
|
77
|
-
def initialize(datetime, flag_time, option, description)
|
78
|
-
@datetime = datetime
|
79
|
-
@flag_time = flag_time
|
80
|
-
@option = option
|
81
|
-
@description = description
|
82
|
-
end
|
83
|
-
|
84
|
-
# return priority of task calculated by equation defined in subclass.
|
85
|
-
def priority
|
86
|
-
raise NotDefinedError
|
87
|
-
end
|
88
|
-
|
89
|
-
def event_dates
|
90
|
-
raise NotDefinedError
|
91
|
-
end
|
92
92
|
end
|
93
93
|
|