aun 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ require 'aun/message'
2
+
3
+ module Aun
4
+ # MessageFormatter
5
+ class MessageFormatter
6
+ KEYS = %w(A Un Owner Origin UserDefined)
7
+
8
+ def self.csv_hearer
9
+ KEYS.join(',')
10
+ end
11
+
12
+ def self.csv(message)
13
+ message.columns.join(',')
14
+ end
15
+
16
+ def self.markdown_table_header
17
+ header = <<-EOS
18
+ |#{KEYS.join('|')}|
19
+ #{'|:--' * KEYS.size}|
20
+ EOS
21
+ header.chomp
22
+ end
23
+
24
+ def self.markdown_table(message)
25
+ "|#{message.columns.join('|')}|"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Aun
2
+ VERSION = '0.0.1'
3
+ end
data/lib/aun_core.rb ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require 'aun/finder'
3
+ require 'aun/definition_manager'
4
+ require 'aun/message'
5
+ require 'aun/message_formatter'
6
+ require 'aun/default_messages'
7
+
8
+ module Aun
9
+ end
data/rubocop-todo.yml ADDED
@@ -0,0 +1,49 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-10-04 01:37:28 +0900 using RuboCop version 0.21.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ AccessorMethodName:
10
+ Enabled: false
11
+
12
+ # Offense count: 3
13
+ AsciiComments:
14
+ Enabled: false
15
+
16
+ # Offense count: 5
17
+ Documentation:
18
+ Enabled: false
19
+
20
+ # Offense count: 1
21
+ EmptyLinesAroundAccessModifier:
22
+ Enabled: false
23
+
24
+ # Offense count: 6
25
+ LineLength:
26
+ Max: 99
27
+
28
+ # Offense count: 2
29
+ RegexpLiteral:
30
+ MaxSlashes: 0
31
+
32
+ # Offense count: 9
33
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
34
+ TrailingComma:
35
+ Enabled: false
36
+
37
+ # Offense count: 2
38
+ # Cop supports --auto-correct.
39
+ # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist.
40
+ TrivialAccessors:
41
+ Enabled: false
42
+
43
+ # Offense count: 32
44
+ UnusedMethodArgument:
45
+ Enabled: false
46
+
47
+ # Offense count: 1
48
+ UselessAssignment:
49
+ Enabled: false
@@ -0,0 +1,315 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'aun/finder'
4
+ require 'aun/default_messages'
5
+
6
+ describe Aun::Finder do
7
+ context :talk do
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'valid key',
12
+ key: '君名前は?',
13
+ expected: '田原年彦'
14
+ },
15
+ {
16
+ case_no: 2,
17
+ case_title: 'not exist key',
18
+ key: '山んば',
19
+ expected: ''
20
+ }
21
+ ]
22
+
23
+ cases.each do |c|
24
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
25
+ begin
26
+ case_before c
27
+
28
+ # -- given --
29
+ aun_message = Aun::Finder.new
30
+
31
+ # -- when --
32
+ actual = aun_message.talk(c[:key])
33
+
34
+ # -- then --
35
+ expect(actual).to eq(c[:expected])
36
+ ensure
37
+ case_after c
38
+ end
39
+ end
40
+
41
+ def case_before(c)
42
+ # implement each case before
43
+ end
44
+
45
+ def case_after(c)
46
+ # implement each case after
47
+ end
48
+ end
49
+ end
50
+
51
+ context :owner_talk do
52
+ cases = [
53
+ {
54
+ case_no: 1,
55
+ case_title: 'valid key',
56
+ key: '君名前は?',
57
+ expected: '田原年彦「田原年彦」'
58
+ },
59
+ {
60
+ case_no: 2,
61
+ case_title: 'not exist key',
62
+ key: '山んば',
63
+ expected: ''
64
+ }
65
+ ]
66
+
67
+ cases.each do |c|
68
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
69
+ begin
70
+ case_before c
71
+
72
+ # -- given --
73
+ aun_message = Aun::Finder.new
74
+
75
+ # -- when --
76
+ actual = aun_message.owner_talk(c[:key])
77
+
78
+ # -- then --
79
+ expect(actual).to eq(c[:expected])
80
+ ensure
81
+ case_after c
82
+ end
83
+ end
84
+
85
+ def case_before(c)
86
+ # implement each case before
87
+ end
88
+
89
+ def case_after(c)
90
+ # implement each case after
91
+ end
92
+ end
93
+ end
94
+
95
+ context :talk_with_origin do
96
+ cases = [
97
+ {
98
+ case_no: 1,
99
+ case_title: 'valid key',
100
+ key: '君名前は?',
101
+ expected: '田原年彦「田原年彦」 from [行け!稲中卓球部]'
102
+ },
103
+ {
104
+ case_no: 2,
105
+ case_title: 'not exist key',
106
+ key: '山んば',
107
+ expected: ''
108
+ }
109
+ ]
110
+
111
+ cases.each do |c|
112
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
113
+ begin
114
+ case_before c
115
+
116
+ # -- given --
117
+ aun_message = Aun::Finder.new
118
+
119
+ # -- when --
120
+ actual = aun_message.talk_with_origin(c[:key])
121
+
122
+ # -- then --
123
+ expect(actual).to eq(c[:expected])
124
+ ensure
125
+ case_after c
126
+ end
127
+ end
128
+
129
+ def case_before(c)
130
+ # implement each case before
131
+ end
132
+
133
+ def case_after(c)
134
+ # implement each case after
135
+ end
136
+ end
137
+ end
138
+
139
+ context :inspect do
140
+ cases = [
141
+ {
142
+ case_no: 1,
143
+ case_title: 'valid key',
144
+ key: '君名前は?',
145
+ expected: "阿:君名前は?\t吽:田原年彦\t発言者:田原年彦\t原典:行け!稲中卓球部,\tユーザー定義:false"
146
+ },
147
+ {
148
+ case_no: 2,
149
+ case_title: 'not exist key',
150
+ key: '山んば',
151
+ expected: ''
152
+ }
153
+ ]
154
+
155
+ cases.each do |c|
156
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
157
+ begin
158
+ case_before c
159
+
160
+ # -- given --
161
+ aun_message = Aun::Finder.new
162
+
163
+ # -- when --
164
+ actual = aun_message.inspect(c[:key])
165
+
166
+ # -- then --
167
+ expect(actual).to eq(c[:expected])
168
+ ensure
169
+ case_after c
170
+ end
171
+ end
172
+
173
+ def case_before(c)
174
+ # implement each case before
175
+ end
176
+
177
+ def case_after(c)
178
+ # implement each case after
179
+ end
180
+ end
181
+ end
182
+
183
+ context :inspect_all do
184
+ cases = [
185
+ {
186
+ case_no: 1,
187
+ case_title: 'valid key',
188
+ expected: <<-EOS
189
+ 阿:君名前は?\t吽:田原年彦\t発言者:田原年彦\t原典:行け!稲中卓球部,\tユーザー定義:false
190
+ 阿:山\t吽:川\t発言者:unknown\t原典:unknown,\tユーザー定義:false
191
+ 阿:ぬるぽ\t吽:ガッ\t発言者:unknown\t原典:unknown,\tユーザー定義:false
192
+ EOS
193
+ }
194
+ ]
195
+
196
+ cases.each do |c|
197
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
198
+ begin
199
+ case_before c
200
+
201
+ # -- given --
202
+ aun_message = Aun::Finder.new
203
+
204
+ # -- when --
205
+ actual = aun_message.inspect_all
206
+
207
+ # -- then --
208
+ expect(actual).to eq(c[:expected].chomp)
209
+ ensure
210
+ case_after c
211
+ end
212
+ end
213
+
214
+ def case_before(c)
215
+ # implement each case before
216
+ end
217
+
218
+ def case_after(c)
219
+ # implement each case after
220
+ end
221
+ end
222
+ end
223
+
224
+ context :aun_definitions do
225
+ cases = [
226
+ {
227
+ case_no: 1,
228
+ case_title: 'valid case',
229
+ expected: Aun::DefaultMessages::MESSAGES
230
+ }
231
+ ]
232
+
233
+ cases.each do |c|
234
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
235
+ begin
236
+ case_before c
237
+
238
+ # -- given --
239
+ aun_message = Aun::Finder.new
240
+
241
+ # -- when --
242
+ # TODO: implement execute code
243
+ actual = aun_message.aun_definitions
244
+
245
+ # -- then --
246
+ expect(actual).to eq(c[:expected])
247
+ ensure
248
+ case_after c
249
+ end
250
+ end
251
+
252
+ def case_before(c)
253
+ # implement each case before
254
+ end
255
+
256
+ def case_after(c)
257
+ # implement each case after
258
+ end
259
+ end
260
+ end
261
+
262
+ context :add_messages do
263
+ ADDITIONAL_MESSAGES = [
264
+ Aun::Message.new(
265
+ 'んーばばんばんば',
266
+ 'めらっさめらっさ',
267
+ owner: 'パプワくん',
268
+ origin: '南国少年パプワくん',
269
+ user_defined: true
270
+ ),
271
+ Aun::Message.new(
272
+ 'ツー',
273
+ 'カー',
274
+ user_defined: true
275
+ )
276
+ ]
277
+
278
+ cases = [
279
+ {
280
+ case_no: 1,
281
+ case_title: 'case_title',
282
+ messages: ADDITIONAL_MESSAGES,
283
+ expected: Aun::DefaultMessages::MESSAGES + ADDITIONAL_MESSAGES
284
+ },
285
+ ]
286
+
287
+ cases.each do |c|
288
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
289
+ begin
290
+ case_before c
291
+
292
+ # -- given --
293
+ aun_message = Aun::Finder.new
294
+
295
+ # -- when --
296
+ aun_message.add_messages(c[:messages])
297
+ actual = aun_message.messages
298
+
299
+ # -- then --
300
+ expect(actual).to eq(c[:expected])
301
+ ensure
302
+ case_after c
303
+ end
304
+ end
305
+
306
+ def case_before(c)
307
+ # implement each case before
308
+ end
309
+
310
+ def case_after(c)
311
+ # implement each case after
312
+ end
313
+ end
314
+ end
315
+ end
@@ -0,0 +1,183 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'aun/message_formatter'
4
+ require 'aun/message'
5
+
6
+ describe Aun::MessageFormatter do
7
+ context :csv_hearer do
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'valid case',
12
+ expected: 'A,Un,Owner,Origin,UserDefined'
13
+ }
14
+ ]
15
+
16
+ cases.each do |c|
17
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
18
+ begin
19
+ case_before c
20
+
21
+ # -- given --
22
+ # nothing
23
+
24
+ # -- when --
25
+ actual = Aun::MessageFormatter.csv_hearer
26
+
27
+ # -- then --
28
+ expect(actual).to eq(c[:expected])
29
+ ensure
30
+ case_after c
31
+ end
32
+ end
33
+
34
+ def case_before(c)
35
+ # implement each case before
36
+ end
37
+
38
+ def case_after(c)
39
+ # implement each case after
40
+ end
41
+ end
42
+ end
43
+
44
+ context :csv do
45
+ cases = [
46
+ {
47
+ case_no: 1,
48
+ case_title: 'all columns case',
49
+ message: Aun::Message.new(
50
+ 'んーばばんばんば',
51
+ 'めらっさめらっさ',
52
+ owner: 'パプワくん',
53
+ origin: '南国少年パプワくん',
54
+ user_defined: true
55
+ ),
56
+ expected: 'んーばばんばんば,めらっさめらっさ,パプワくん,南国少年パプワくん,true'
57
+ },
58
+ {
59
+ case_no: 2,
60
+ case_title: 'part columns case',
61
+ message: Aun::Message.new('ツー', 'カー', user_defined: true),
62
+ expected: 'ツー,カー,unknown,unknown,true'
63
+ }
64
+ ]
65
+
66
+ cases.each do |c|
67
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
68
+ begin
69
+ case_before c
70
+
71
+ # -- given --
72
+ # nothing
73
+
74
+ # -- when --
75
+ actual = Aun::MessageFormatter.csv(c[:message])
76
+
77
+ # -- then --
78
+ expect(actual).to eq(c[:expected])
79
+ ensure
80
+ case_after c
81
+ end
82
+ end
83
+
84
+ def case_before(c)
85
+ # implement each case before
86
+ end
87
+
88
+ def case_after(c)
89
+ # implement each case after
90
+ end
91
+ end
92
+ end
93
+
94
+ context :markdown_table_header do
95
+ cases = [
96
+ {
97
+ case_no: 1,
98
+ case_title: 'valid case',
99
+ expected: <<-EOS
100
+ |A|Un|Owner|Origin|UserDefined|
101
+ |:--|:--|:--|:--|:--|
102
+ EOS
103
+ },
104
+ ]
105
+
106
+ cases.each do |c|
107
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
108
+ begin
109
+ case_before c
110
+
111
+ # -- given --
112
+ # nothing
113
+
114
+ # -- when --
115
+ actual = Aun::MessageFormatter.markdown_table_header
116
+
117
+ # -- then --
118
+ expect(actual).to eq(c[:expected].chomp)
119
+ ensure
120
+ case_after c
121
+ end
122
+ end
123
+
124
+ def case_before(c)
125
+ # implement each case before
126
+ end
127
+
128
+ def case_after(c)
129
+ # implement each case after
130
+ end
131
+ end
132
+ end
133
+
134
+ context :markdown_table do
135
+ cases = [
136
+ {
137
+ case_no: 1,
138
+ case_title: 'all columns case',
139
+ message: Aun::Message.new(
140
+ 'んーばばんばんば',
141
+ 'めらっさめらっさ',
142
+ owner: 'パプワくん',
143
+ origin: '南国少年パプワくん',
144
+ user_defined: true
145
+ ),
146
+ expected: '|んーばばんばんば|めらっさめらっさ|パプワくん|南国少年パプワくん|true|'
147
+ },
148
+ {
149
+ case_no: 2,
150
+ case_title: 'part columns case',
151
+ message: Aun::Message.new('ツー', 'カー', user_defined: true),
152
+ expected: '|ツー|カー|unknown|unknown|true|'
153
+ }
154
+ ]
155
+
156
+ cases.each do |c|
157
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
158
+ begin
159
+ case_before c
160
+
161
+ # -- given --
162
+ # nothing
163
+
164
+ # -- when --
165
+ actual = Aun::MessageFormatter.markdown_table(c[:message])
166
+
167
+ # -- then --
168
+ expect(actual).to eq(c[:expected])
169
+ ensure
170
+ case_after c
171
+ end
172
+ end
173
+
174
+ def case_before(c)
175
+ # implement each case before
176
+ end
177
+
178
+ def case_after(c)
179
+ # implement each case after
180
+ end
181
+ end
182
+ end
183
+ end