qiita_matome 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +22 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +0 -0
  6. data/.travis.yml +8 -0
  7. data/CONTRIBUTING.md +44 -0
  8. data/Gemfile +13 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +210 -0
  11. data/Rakefile +8 -0
  12. data/bin/qiitam +34 -0
  13. data/lib/display.rb +10 -0
  14. data/lib/display/display_consts.rb +35 -0
  15. data/lib/display/displayer.rb +81 -0
  16. data/lib/file_writer.rb +19 -0
  17. data/lib/models/article.rb +38 -0
  18. data/lib/models/articles.rb +40 -0
  19. data/lib/qiita_json_loader.rb +43 -0
  20. data/lib/qiita_matome/version.rb +4 -0
  21. data/lib/qiita_matome_core.rb +121 -0
  22. data/lib/qiita_matome_dsl.rb +31 -0
  23. data/lib/qiita_matome_dsl_model.rb +37 -0
  24. data/lib/sort.rb +10 -0
  25. data/lib/sort/sort_consts.rb +28 -0
  26. data/lib/sort/sorter.rb +51 -0
  27. data/lib/validators.rb +13 -0
  28. data/lib/validators/article_validator.rb +19 -0
  29. data/lib/validators/articles_validator.rb +16 -0
  30. data/lib/validators/display_columns_validator.rb +41 -0
  31. data/lib/validators/sort_type_validator.rb +19 -0
  32. data/manual_test_docs/.gitkeep +0 -0
  33. data/qiita_matome.gemspec +28 -0
  34. data/samples/matome_title_asc.md +25 -0
  35. data/spec/display/displayer_spec.rb +341 -0
  36. data/spec/file_writer_spec.rb +92 -0
  37. data/spec/models/article_spec.rb +131 -0
  38. data/spec/models/articles_spec.rb +305 -0
  39. data/spec/qiita_matome_core_spec.rb +46 -0
  40. data/spec/sort/sorter_spec.rb +392 -0
  41. data/spec/spec_helper.rb +16 -0
  42. data/spec/validators/article_validator_spec.rb +53 -0
  43. data/spec/validators/articles_validator_spec.rb +54 -0
  44. data/spec/validators/display_columns_validator_spec.rb +58 -0
  45. data/spec/validators/sort_type_validator_spec.rb +54 -0
  46. metadata +202 -0
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'file_writer'
4
+ require 'fileutils'
5
+
6
+ # rubocop:disable LineLength, UnusedMethodArgument
7
+ describe QiitaMatome::FileWriter do
8
+ context :new do
9
+ cases = [
10
+ {
11
+ case_no: 1,
12
+ case_title: 'valid output path',
13
+ contents: "hoge\nhige",
14
+ output_file: './tmp/output.md',
15
+ expected: './tmp/output.md'
16
+ }
17
+ ]
18
+
19
+ cases.each do |c|
20
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
21
+ begin
22
+ case_before c
23
+
24
+ # -- given --
25
+ file_writer = QiitaMatome::FileWriter.new(c[:output_file], c[:contents])
26
+
27
+ # -- when --
28
+ actual = file_writer.output_file
29
+
30
+ # -- then --
31
+ expect(actual).to eq(c[:expected])
32
+ ensure
33
+ case_after c
34
+ end
35
+ end
36
+
37
+ def case_before(c)
38
+ # implement each case before
39
+ end
40
+
41
+ def case_after(c)
42
+ # implement each case after
43
+ end
44
+ end
45
+ end
46
+
47
+ context :write do
48
+ WRITE_TMP = 'write_tmp'
49
+ cases = [
50
+ {
51
+ case_no: 1,
52
+ case_title: 'valid output path',
53
+ contents: "hoge\nhige",
54
+ output_file: './tmp/output.md',
55
+ expected: "hoge\nhige"
56
+ }
57
+ ]
58
+
59
+ cases.each do |c|
60
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
61
+ begin
62
+ case_before c
63
+
64
+ # -- given --
65
+ file_writer = QiitaMatome::FileWriter.new(c[:output_file], c[:contents])
66
+
67
+ # -- when --
68
+ file_writer.write
69
+ actual = File.read(c[:output_file])
70
+
71
+ # -- then --
72
+ expect(actual).to eq(c[:expected])
73
+ ensure
74
+ case_after c
75
+ end
76
+ end
77
+
78
+ def case_before(c)
79
+ # implement each case before
80
+ Dir.mkdir(WRITE_TMP) unless Dir.exist? WRITE_TMP
81
+ Dir.chdir(WRITE_TMP)
82
+ end
83
+
84
+ def case_after(c)
85
+ # implement each case after
86
+ Dir.chdir('../')
87
+ FileUtils.rm_rf(WRITE_TMP) if Dir.exist? WRITE_TMP
88
+ end
89
+ end
90
+ end
91
+ end
92
+ # rubocop:enable LineLength, UnusedMethodArgument
@@ -0,0 +1,131 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'models/article'
4
+
5
+ # rubocop:disable LineLength, UnusedMethodArgument
6
+ describe QiitaMatome::Article do
7
+ context :created_at_ymdhms do
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: '2 list case',
12
+ init: {
13
+ 'created_at' => '2014-06-17 21:29:59 +0900',
14
+ 'updated_at' => '2014-06-18 20:28:58 +0900'
15
+ },
16
+ expected: '2014/06/17 21:29:59'
17
+ }
18
+ ]
19
+
20
+ cases.each do |c|
21
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
22
+ begin
23
+ case_before c
24
+
25
+ # -- given --
26
+ article = QiitaMatome::Article.new(c[:init])
27
+
28
+ # -- when --
29
+ actual = article.created_at_ymdhms
30
+
31
+ # -- then --
32
+ expect(actual).to eq(c[:expected])
33
+ ensure
34
+ case_after c
35
+ end
36
+ end
37
+
38
+ def case_before(_c)
39
+ # implement each case before
40
+ end
41
+
42
+ def case_after(_c)
43
+ # implement each case after
44
+ end
45
+ end
46
+ end
47
+
48
+ context :updated_at_ymdhms do
49
+ cases = [
50
+ {
51
+ case_no: 1,
52
+ case_title: '2 list case',
53
+ init: {
54
+ 'created_at' => '2014-06-17 21:29:59 +0900',
55
+ 'updated_at' => '2014-06-18 20:28:58 +0900'
56
+ },
57
+ expected: '2014/06/18 20:28:58'
58
+ }
59
+ ]
60
+
61
+ cases.each do |c|
62
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
63
+ begin
64
+ case_before c
65
+
66
+ # -- given --
67
+ article = QiitaMatome::Article.new(c[:init])
68
+
69
+ # -- when --
70
+ actual = article.updated_at_ymdhms
71
+
72
+ # -- then --
73
+ expect(actual).to eq(c[:expected])
74
+ ensure
75
+ case_after c
76
+ end
77
+ end
78
+
79
+ def case_before(_c)
80
+ # implement each case before
81
+ end
82
+
83
+ def case_after(_c)
84
+ # implement each case after
85
+ end
86
+ end
87
+ end
88
+
89
+ context :title_link do
90
+ cases = [
91
+ {
92
+ case_no: 1,
93
+ case_title: '2 list case',
94
+ init: {
95
+ 'title' => 'title | subtitle',
96
+ 'uuid' => '123',
97
+ 'user' => { 'url_name' => 'tbpgr' }
98
+ },
99
+ expected: '[title subtitle](http://qiita.com/tbpgr/items/123)'
100
+ }
101
+ ]
102
+
103
+ cases.each do |c|
104
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
105
+ begin
106
+ case_before c
107
+
108
+ # -- given --
109
+ article = QiitaMatome::Article.new(c[:init])
110
+
111
+ # -- when --
112
+ actual = article.title_link
113
+
114
+ # -- then --
115
+ expect(actual).to eq(c[:expected])
116
+ ensure
117
+ case_after c
118
+ end
119
+ end
120
+
121
+ def case_before(_c)
122
+ # implement each case before
123
+ end
124
+
125
+ def case_after(_c)
126
+ # implement each case after
127
+ end
128
+ end
129
+ end
130
+ end
131
+ # rubocop:enable LineLength, UnusedMethodArgument
@@ -0,0 +1,305 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'models/articles'
4
+ require 'models/article'
5
+
6
+ # rubocop:disable LineLength, UnusedMethodArgument
7
+ describe QiitaMatome::Articles do
8
+ context :<< do
9
+ cases = [
10
+ {
11
+ case_no: 1,
12
+ case_title: '2 list case',
13
+ appends: [QiitaMatome::Article.new, QiitaMatome::Article.new],
14
+ expected: 2
15
+ },
16
+ {
17
+ case_no: 2,
18
+ case_title: '1 list case',
19
+ appends: [QiitaMatome::Article.new],
20
+ expected: 1
21
+ }
22
+ ]
23
+
24
+ cases.each do |c|
25
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
26
+ begin
27
+ case_before c
28
+
29
+ # -- given --
30
+ qiita_matome_articles = QiitaMatome::Articles.new
31
+
32
+ # -- when --
33
+ c[:appends].each { |e|qiita_matome_articles << e }
34
+ actual = qiita_matome_articles.size
35
+
36
+ # -- then --
37
+ expect(actual).to eq(c[:expected])
38
+ ensure
39
+ case_after c
40
+ end
41
+ end
42
+
43
+ def case_before(_c)
44
+ # implement each case before
45
+ end
46
+
47
+ def case_after(_c)
48
+ # implement each case after
49
+ end
50
+ end
51
+ end
52
+
53
+ context :+ do
54
+ cases = [
55
+ {
56
+ case_no: 1,
57
+ case_title: 'init 0 append 2 list case',
58
+ init: [],
59
+ appends: QiitaMatome::Articles.new([QiitaMatome::Article.new, QiitaMatome::Article.new]),
60
+ expected: 2
61
+ },
62
+ {
63
+ case_no: 2,
64
+ case_title: 'init 2 append 2 list case',
65
+ init: [QiitaMatome::Article.new, QiitaMatome::Article.new],
66
+ appends: QiitaMatome::Articles.new([QiitaMatome::Article.new, QiitaMatome::Article.new]),
67
+ expected: 4
68
+ }
69
+ ]
70
+
71
+ cases.each do |c|
72
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
73
+ begin
74
+ case_before c
75
+
76
+ # -- given --
77
+ qiita_matome_articles = QiitaMatome::Articles.new(c[:init])
78
+
79
+ # -- when --
80
+ qiita_matome_articles += c[:appends]
81
+ actual = qiita_matome_articles.size
82
+
83
+ # -- then --
84
+ expect(actual).to eq(c[:expected])
85
+ ensure
86
+ case_after c
87
+ end
88
+ end
89
+
90
+ def case_before(_c)
91
+ # implement each case before
92
+ end
93
+
94
+ def case_after(_c)
95
+ # implement each case after
96
+ end
97
+ end
98
+ end
99
+
100
+ context :size do
101
+ cases = [
102
+ {
103
+ case_no: 1,
104
+ case_title: '2 list case',
105
+ articles: [QiitaMatome::Article.new, QiitaMatome::Article.new],
106
+ expected: 2
107
+ },
108
+ {
109
+ case_no: 2,
110
+ case_title: 'empty list case',
111
+ articles: [],
112
+ expected: 0
113
+ }
114
+ ]
115
+
116
+ cases.each do |c|
117
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
118
+ begin
119
+ case_before c
120
+
121
+ # -- given --
122
+ qiita_matome_articles = QiitaMatome::Articles.new(c[:articles])
123
+
124
+ # -- when --
125
+ actual = qiita_matome_articles.size
126
+
127
+ # -- then --
128
+ expect(actual).to eq(c[:expected])
129
+ ensure
130
+ case_after c
131
+ end
132
+ end
133
+
134
+ def case_before(_c)
135
+ # implement each case before
136
+ end
137
+
138
+ def case_after(_c)
139
+ # implement each case after
140
+ end
141
+ end
142
+ end
143
+
144
+ context :each do
145
+ cases = [
146
+ {
147
+ case_no: 1,
148
+ case_title: '2 list case',
149
+ articles: [QiitaMatome::Article.new('user' => 1), QiitaMatome::Article.new('user' => 2)],
150
+ expected: 3
151
+ }
152
+ ]
153
+
154
+ cases.each do |c|
155
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
156
+ begin
157
+ case_before c
158
+
159
+ # -- given --
160
+ qiita_matome_articles = QiitaMatome::Articles.new(c[:articles])
161
+
162
+ # -- when --
163
+ total = 0
164
+ qiita_matome_articles.each { |e|total += e.user }
165
+
166
+ # -- then --
167
+ expect(total).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 :filter_by_tag do
184
+ cases = [
185
+ {
186
+ case_no: 1,
187
+ case_title: 'init 4 Ruby-tag 2 list case',
188
+ init: [
189
+ QiitaMatome::Article.new('tags' => [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => 'icon', 'versions' => [] }]),
190
+ QiitaMatome::Article.new('tags' => [{ 'name' => 'Java', 'url_name' => 'java', 'icon_url' => 'icon', 'versions' => [] }]),
191
+ QiitaMatome::Article.new('tags' => [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => 'icon', 'versions' => [] }]),
192
+ QiitaMatome::Article.new('tags' => [{ 'name' => 'C', 'url_name' => 'c', 'icon_url' => 'icon', 'versions' => [] }])
193
+ ],
194
+ filter_tag: 'Ruby',
195
+ expected: 2
196
+ },
197
+ {
198
+ case_no: 1,
199
+ case_title: 'init 4 Swift-tag 0 list case',
200
+ init: [
201
+ QiitaMatome::Article.new('tags' => [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => 'icon', 'versions' => [] }]),
202
+ QiitaMatome::Article.new('tags' => [{ 'name' => 'Java', 'url_name' => 'java', 'icon_url' => 'icon', 'versions' => [] }]),
203
+ QiitaMatome::Article.new('tags' => [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => 'icon', 'versions' => [] }]),
204
+ QiitaMatome::Article.new('tags' => [{ 'name' => 'C', 'url_name' => 'c', 'icon_url' => 'icon', 'versions' => [] }])
205
+ ],
206
+ filter_tag: 'Swift',
207
+ expected: 0
208
+ }
209
+ ]
210
+
211
+ cases.each do |c|
212
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
213
+ begin
214
+ case_before c
215
+
216
+ # -- given --
217
+ qiita_matome_articles = QiitaMatome::Articles.new(c[:init])
218
+
219
+ # -- when --
220
+ actual = qiita_matome_articles.filter_by_tag(c[:filter_tag])
221
+
222
+ # -- then --
223
+ expect(actual.size).to eq(c[:expected])
224
+ ensure
225
+ case_after c
226
+ end
227
+ end
228
+
229
+ def case_before(_c)
230
+ # implement each case before
231
+ end
232
+
233
+ def case_after(_c)
234
+ # implement each case after
235
+ end
236
+ end
237
+ end
238
+
239
+ context :exclude_uuid do
240
+ cases = [
241
+ {
242
+ case_no: 1,
243
+ case_title: 'exclude uuid case',
244
+ init: [
245
+ QiitaMatome::Article.new('title' => 'title1', 'uuid' => '1'),
246
+ QiitaMatome::Article.new('title' => 'title2', 'uuid' => '2'),
247
+ QiitaMatome::Article.new('title' => 'title3', 'uuid' => '3'),
248
+ QiitaMatome::Article.new('title' => 'title4', 'uuid' => '4')
249
+ ],
250
+ uuids: %w(2 3),
251
+ expected: [
252
+ QiitaMatome::Article.new('title' => 'title1', 'uuid' => '1'),
253
+ QiitaMatome::Article.new('title' => 'title4', 'uuid' => '4')
254
+ ]
255
+ },
256
+ {
257
+ case_no: 2,
258
+ case_title: 'exclude uuid case(no target)',
259
+ init: [
260
+ QiitaMatome::Article.new('title' => 'title1', 'uuid' => '1'),
261
+ QiitaMatome::Article.new('title' => 'title2', 'uuid' => '2'),
262
+ QiitaMatome::Article.new('title' => 'title3', 'uuid' => '3'),
263
+ QiitaMatome::Article.new('title' => 'title4', 'uuid' => '4')
264
+ ],
265
+ uuids: ['5'],
266
+ expected: [
267
+ QiitaMatome::Article.new('title' => 'title1', 'uuid' => '1'),
268
+ QiitaMatome::Article.new('title' => 'title2', 'uuid' => '2'),
269
+ QiitaMatome::Article.new('title' => 'title3', 'uuid' => '3'),
270
+ QiitaMatome::Article.new('title' => 'title4', 'uuid' => '4')
271
+ ]
272
+ }
273
+ ]
274
+
275
+ cases.each do |c|
276
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
277
+ begin
278
+ case_before c
279
+
280
+ # -- given --
281
+ # nothing
282
+
283
+ # -- when --
284
+ actual = QiitaMatome::Articles.exclude_uuid(c[:init], c[:uuids])
285
+
286
+ # -- then --
287
+ actual.each_with_index do |e, i|
288
+ expect(e.title).to eq(c[:expected][i].title)
289
+ end
290
+ ensure
291
+ case_after c
292
+ end
293
+ end
294
+
295
+ def case_before(_c)
296
+ # implement each case before
297
+ end
298
+
299
+ def case_after(_c)
300
+ # implement each case after
301
+ end
302
+ end
303
+ end
304
+ end
305
+ # rubocop:enable LineLength, UnusedMethodArgument