tudu 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,120 +1,120 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
- require "tudu_dsl"
4
-
5
- describe Tudu::Dsl do
6
- context :target_type do
7
- cases = [
8
- {
9
- case_no: 1,
10
- case_title: "valid type String",
11
- input_type: "mail",
12
- expected: :mail
13
- },
14
- {
15
- case_no: 2,
16
- case_title: "valid type Symbol",
17
- input_type: :mail,
18
- expected: :mail
19
- },
20
- {
21
- case_no: 3,
22
- case_title: "invalid type nil",
23
- input_type: nil,
24
- expected: :none
25
- },
26
- {
27
- case_no: 4,
28
- case_title: "invalid type not Symbol or String",
29
- input_type: 123,
30
- expected: :none
31
- },
32
- {
33
- case_no: 5,
34
- case_title: "invalid type",
35
- input_type: :invalid,
36
- expected: :none
37
- },
38
- ]
39
-
40
- cases.each do |c|
41
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
42
- begin
43
- case_before c
44
-
45
- # -- given --
46
- tudu_dsl = Tudu::Dsl.new
47
-
48
- # -- when --
49
- tudu_dsl.target_type c[:input_type]
50
-
51
- # -- then --
52
- actual = tudu_dsl._target_type
53
- expect(actual).to eq(c[:expected])
54
- ensure
55
- case_after c
56
- end
57
- end
58
-
59
- def case_before(c)
60
- # implement each case before
61
- end
62
-
63
- def case_after(c)
64
- # implement each case after
65
- end
66
- end
67
- end
68
-
69
- context :targets do
70
- cases = [
71
- {
72
- case_no: 1,
73
- case_title: "valid type Array",
74
- input_type: ["tbpgr@tbpgr.jp", "tbpgr@tbpgr.jp"],
75
- expected: ["tbpgr@tbpgr.jp", "tbpgr@tbpgr.jp"]
76
- },
77
- {
78
- case_no: 2,
79
- case_title: "invalid type",
80
- input_type: "tbpgr@tbpgr.jp",
81
- expected: []
82
- },
83
- {
84
- case_no: 3,
85
- case_title: "invalid type nil",
86
- input_type: nil,
87
- expected: []
88
- },
89
- ]
90
-
91
- cases.each do |c|
92
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
93
- begin
94
- case_before c
95
-
96
- # -- given --
97
- tudu_dsl = Tudu::Dsl.new
98
-
99
- # -- when --
100
- tudu_dsl.targets c[:input_type]
101
-
102
- # -- then --
103
- actual = tudu_dsl._targets
104
- expect(actual).to eq(c[:expected])
105
- ensure
106
- case_after c
107
- end
108
- end
109
-
110
- def case_before(c)
111
- # implement each case before
112
- end
113
-
114
- def case_after(c)
115
- # implement each case after
116
- end
117
- end
118
- end
119
-
120
- end
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "tudu_dsl"
4
+
5
+ describe Tudu::Dsl do
6
+ context :target_type do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: "valid type String",
11
+ input_type: "mail",
12
+ expected: :mail
13
+ },
14
+ {
15
+ case_no: 2,
16
+ case_title: "valid type Symbol",
17
+ input_type: :mail,
18
+ expected: :mail
19
+ },
20
+ {
21
+ case_no: 3,
22
+ case_title: "invalid type nil",
23
+ input_type: nil,
24
+ expected: :none
25
+ },
26
+ {
27
+ case_no: 4,
28
+ case_title: "invalid type not Symbol or String",
29
+ input_type: 123,
30
+ expected: :none
31
+ },
32
+ {
33
+ case_no: 5,
34
+ case_title: "invalid type",
35
+ input_type: :invalid,
36
+ expected: :none
37
+ },
38
+ ]
39
+
40
+ cases.each do |c|
41
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
42
+ begin
43
+ case_before c
44
+
45
+ # -- given --
46
+ tudu_dsl = Tudu::Dsl.new
47
+
48
+ # -- when --
49
+ tudu_dsl.target_type c[:input_type]
50
+
51
+ # -- then --
52
+ actual = tudu_dsl._target_type
53
+ expect(actual).to eq(c[:expected])
54
+ ensure
55
+ case_after c
56
+ end
57
+ end
58
+
59
+ def case_before(c)
60
+ # implement each case before
61
+ end
62
+
63
+ def case_after(c)
64
+ # implement each case after
65
+ end
66
+ end
67
+ end
68
+
69
+ context :targets do
70
+ cases = [
71
+ {
72
+ case_no: 1,
73
+ case_title: "valid type Array",
74
+ input_type: ["tbpgr@tbpgr.jp", "tbpgr@tbpgr.jp"],
75
+ expected: ["tbpgr@tbpgr.jp", "tbpgr@tbpgr.jp"]
76
+ },
77
+ {
78
+ case_no: 2,
79
+ case_title: "invalid type",
80
+ input_type: "tbpgr@tbpgr.jp",
81
+ expected: []
82
+ },
83
+ {
84
+ case_no: 3,
85
+ case_title: "invalid type nil",
86
+ input_type: nil,
87
+ expected: []
88
+ },
89
+ ]
90
+
91
+ cases.each do |c|
92
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
93
+ begin
94
+ case_before c
95
+
96
+ # -- given --
97
+ tudu_dsl = Tudu::Dsl.new
98
+
99
+ # -- when --
100
+ tudu_dsl.targets c[:input_type]
101
+
102
+ # -- then --
103
+ actual = tudu_dsl._targets
104
+ expect(actual).to eq(c[:expected])
105
+ ensure
106
+ case_after c
107
+ end
108
+ end
109
+
110
+ def case_before(c)
111
+ # implement each case before
112
+ end
113
+
114
+ def case_after(c)
115
+ # implement each case after
116
+ end
117
+ end
118
+ end
119
+
120
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tudu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-12 00:00:00.000000000 Z
12
+ date: 2013-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &26198988 !ruby/object:Gem::Requirement
16
+ requirement: &26260368 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.18.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *26198988
24
+ version_requirements: *26260368
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &26198220 !ruby/object:Gem::Requirement
27
+ requirement: &26259588 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.14.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *26198220
35
+ version_requirements: *26259588
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: simplecov
38
- requirement: &26197740 !ruby/object:Gem::Requirement
38
+ requirement: &26259132 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.8.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *26197740
46
+ version_requirements: *26259132
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &26196720 !ruby/object:Gem::Requirement
49
+ requirement: &26258124 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '1.3'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *26196720
57
+ version_requirements: *26258124
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &26196108 !ruby/object:Gem::Requirement
60
+ requirement: &26257524 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *26196108
68
+ version_requirements: *26257524
69
69
  description: Single person's minimum unit of task manager
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -81,13 +81,12 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - bin/tudu
84
- - lib/task.rb
85
84
  - lib/tasks.rb
86
85
  - lib/tudu/version.rb
87
86
  - lib/tudu_core.rb
88
87
  - lib/tudu_dsl.rb
89
88
  - spec/spec_helper.rb
90
- - spec/task_spec.rb
89
+ - spec/tasks_spec.rb
91
90
  - spec/tudu_core_spec.rb
92
91
  - spec/tudu_dsl_spec.rb
93
92
  - tudu.gemspec
@@ -118,7 +117,7 @@ specification_version: 3
118
117
  summary: Single person's minimum unit of task manager
119
118
  test_files:
120
119
  - spec/spec_helper.rb
121
- - spec/task_spec.rb
120
+ - spec/tasks_spec.rb
122
121
  - spec/tudu_core_spec.rb
123
122
  - spec/tudu_dsl_spec.rb
124
123
  has_rdoc:
data/lib/task.rb DELETED
@@ -1,281 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Tudu
4
- #= Tudu::Tasks
5
- class Tasks
6
- #== Tudufile key
7
- TUDU_FILE_KEY = :tudufile
8
- #== todo key
9
- TUDU_TODO_KEY = :todo
10
- #== doing key
11
- TUDU_DOING_KEY = :doing
12
- #== done key
13
- TUDU_DONE_KEY = :done
14
- #== file's key
15
- TUDU_KEYS = [TUDU_FILE_KEY, TUDU_TODO_KEY, TUDU_DOING_KEY, TUDU_DONE_KEY]
16
-
17
- #== Tudufile file name
18
- TUDU_FILE = "Tudufile"
19
- #== Tudufile file name
20
- TUDU_DIR = "tudu"
21
- #== todo file name
22
- TUDU_TODOS_FILE = "todos"
23
- #== todo file path
24
- TUDU_TODOS_FILE_PATH = "./#{TUDU_DIR}/#{TUDU_TODOS_FILE}"
25
- #== doing file name
26
- TUDU_DOINGS_FILE = "doings"
27
- #== doing file path
28
- TUDU_DOINGS_FILE_PATH = "./#{TUDU_DIR}/#{TUDU_DOINGS_FILE}"
29
- #== done file name
30
- TUDU_DONES_FILE = "dones"
31
- #== done file path
32
- TUDU_DONES_FILE_PATH = "./#{TUDU_DIR}/#{TUDU_DONES_FILE}"
33
- #== file names
34
- INIT_FILES = {
35
- TUDU_FILE_KEY => TUDU_FILE,
36
- TUDU_TODO_KEY => TUDU_TODOS_FILE,
37
- TUDU_DOING_KEY => TUDU_DOINGS_FILE,
38
- TUDU_DONE_KEY => TUDU_DONES_FILE
39
- }
40
- #== task file names
41
- TASK_FILES = {
42
- TUDU_TODO_KEY => TUDU_TODOS_FILE,
43
- TUDU_DOING_KEY => TUDU_DOINGS_FILE,
44
- TUDU_DONE_KEY => TUDU_DONES_FILE
45
- }
46
-
47
- #== Tudufile file template
48
- TUDU_FILE_TEMPLATE =<<-EOS
49
- # encoding: utf-8
50
-
51
- # !!!!!!! in tudu ver 0.0.1 this file not using !!!!!!!
52
-
53
- # if you want to use notification, set target type. default => :none
54
- # you can set :none, :mail
55
- # target_type :mail
56
-
57
- # if you want to use notification, set targets. default => []
58
- # if you choose target_type none, you must not set targets.
59
- # if you choose mail, you must set target email addresses.
60
- # targets ["target1@abcdefg", "target2@abcdefg"]
61
- EOS
62
-
63
- #== todo file template
64
- TUDU_TODOS_FILE_TEMPLATE = ""
65
- #== doing file template
66
- TUDU_DOINGS_FILE_TEMPLATE = ""
67
- #== done file template
68
- TUDU_DONES_FILE_TEMPLATE = ""
69
-
70
- #== template files
71
- INIT_FILES_TEMPLATE = {
72
- TUDU_FILE_KEY => TUDU_FILE_TEMPLATE,
73
- TUDU_TODO_KEY => TUDU_TODOS_FILE_TEMPLATE,
74
- TUDU_DOING_KEY => TUDU_DOINGS_FILE_TEMPLATE,
75
- TUDU_DONE_KEY => TUDU_DONES_FILE_TEMPLATE
76
- }
77
-
78
- #== task type [todo, doing, done]
79
- attr_accessor :type
80
- #== task name [uniq]
81
- attr_accessor :name
82
-
83
- class << self
84
- #== add task to todos
85
- #=== Params
86
- #- task_names : add task name list
87
- def add(*task_names)
88
- task_names.each do |task_name|
89
- if find_tasks(task_name)
90
- puts "#{task_name} is already exists."
91
- next
92
- end
93
- File.open(TUDU_TODOS_FILE_PATH, "a:UTF-8") {|f|f.puts task_name}
94
- puts "complete add todo '#{task_name}' to tudu/todos"
95
- end
96
- end
97
-
98
- #== remove task to todo
99
- #=== Params
100
- #- task_names : remove task name list
101
- def remove(*task_names)
102
- task_names.each do |task_name|
103
- can_find = false
104
- TASK_FILES.each_value do |rf|
105
- tasks = get_tasks_from_file(rf)
106
- next unless has_task?(tasks, task_name)
107
- remove_task(tasks, task_name, "./#{TUDU_DIR}/#{rf}")
108
- can_find = true
109
- break
110
- end
111
- puts "no such todo '#{task_name}'" unless can_find
112
- end
113
- end
114
-
115
- #== choose todo => doing task
116
- #=== Params
117
- #- task_name : target task name
118
- def choose(task_name)
119
- if get_doings.size > 0
120
- puts "before choose, you must done current doings."
121
- return
122
- end
123
-
124
- task = find_tasks(task_name)
125
-
126
- if task.nil?
127
- puts "#{task_name} not exists"
128
- return
129
- end
130
-
131
- unless task.todo?
132
- puts "#{task_name} is not exists in todos. #{task_name} in #{task.type}"
133
- return
134
- end
135
-
136
- remove task_name
137
- File.open(TUDU_DOINGS_FILE_PATH, "w:UTF-8") {|f|f.puts task_name}
138
- puts "complete add doings '#{task_name}'"
139
- end
140
-
141
- #== doing to done
142
- #- if doings size == 0, nothing todo.
143
- #- after move doing to done, next todo move to doing.
144
- def done
145
- return unless doings_to_dones
146
- todos_to_doings
147
- end
148
-
149
- #== get todos type tasks.
150
- #=== Returns
151
- # return Array[Tasks]
152
- def get_todos
153
- get_tasks(TUDU_TODOS_FILE)
154
- end
155
-
156
- #== get doings type tasks.
157
- #=== Returns
158
- # return Array[Tasks]
159
- def get_doings
160
- get_tasks(TUDU_DOINGS_FILE)
161
- end
162
-
163
- #== get dones type tasks.
164
- #=== Returns
165
- # return Array[Tasks]
166
- def get_dones
167
- get_tasks(TUDU_DONES_FILE)
168
- end
169
-
170
- #== get each type tasks.
171
- #=== Params
172
- #- type : task type.if use nil, you can get all types task.
173
- #=== Returns
174
- # return Array[Tasks]
175
- def get_tasks(type = nil)
176
- type.nil? ? get_all_tasks : get_each_tasks(type)
177
- end
178
-
179
- #== get each type tasks from file.
180
- #=== Params
181
- #- type : task type.
182
- #=== Returns
183
- # return Array[String]
184
- def get_tasks_from_file(file_name)
185
- File.read("./#{TUDU_DIR}/#{file_name}").split("\n")
186
- end
187
-
188
- #== filter tasklist by search_word.
189
- #=== Params
190
- #- tasks : task list.
191
- #- search_word : filtering word.
192
- #=== Returns
193
- # return filterd task list
194
- def filter_tasks(tasks, search_word)
195
- return tasks if search_word.nil?
196
- tasks.select {|task|task.name.match /.*#{search_word}.*/}
197
- end
198
-
199
- #== find task from all tasks.
200
- #=== Params
201
- #- task_name : task name.
202
- #=== Returns
203
- # return task
204
- def find_tasks(task_name)
205
- tasks = get_tasks
206
- tasks.select {|task|task.name == task_name}.first
207
- end
208
-
209
- private
210
- def get_each_tasks(type)
211
- tasks = []
212
- get_tasks_from_file(type).each {|task|tasks << Tasks.new(type, task)}
213
- tasks
214
- end
215
-
216
- def get_all_tasks
217
- tasks = []
218
- TASK_FILES.each_value {|each_type|tasks += get_each_tasks(each_type)}
219
- tasks
220
- end
221
-
222
- def has_task?(tasks, task_name)
223
- tasks.include? task_name
224
- end
225
-
226
- def remove_task(tasks, task_name, file_path)
227
- tasks.delete(task_name)
228
- File.open(file_path, "w:UTF-8") {|wf|wf.puts tasks.join("\n")}
229
- puts "complete remove todo '#{task_name}' from #{file_path}"
230
- end
231
-
232
- def doings_to_dones
233
- _doings = get_doings
234
- if _doings.size == 0
235
- puts "there is no doing task.before done, you must choose task."
236
- return false
237
- end
238
- File.open(TUDU_DOINGS_FILE_PATH, "w:UTF-8") {|f|f.print ""}
239
- File.open(TUDU_DONES_FILE_PATH, "a:UTF-8") {|f|f.puts _doings.first.name}
240
- true
241
- end
242
-
243
- def todos_to_doings
244
- _todos = get_todos
245
- return if _todos.size == 0
246
- deleted_todos = _todos.dup
247
- deleted_todos.delete_at 0
248
- File.open(TUDU_TODOS_FILE_PATH, "w:UTF-8") do |f|
249
- deleted_todos.each {|task|f.puts task.name}
250
- end
251
- File.open(TUDU_DOINGS_FILE_PATH, "w:UTF-8") {|f|f.puts _todos.first.name}
252
- end
253
- end
254
-
255
- #== init task with setting task type and task name.
256
- def initialize(type, name)
257
- @type, @name = type, name
258
- end
259
-
260
- def todo?
261
- @type == "todos"
262
- end
263
-
264
- def doing?
265
- @type == "doings"
266
- end
267
-
268
- def done?
269
- @type == "dones"
270
- end
271
-
272
- def ==(other)
273
- if self.name == other.name
274
- if self.type == other.type
275
- return true
276
- end
277
- end
278
- false
279
- end
280
- end
281
- end