daigaku 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +5 -0
  5. data/README.md +62 -0
  6. data/Rakefile +2 -0
  7. data/bin/daigaku +12 -0
  8. data/daigaku.gemspec +37 -0
  9. data/lib/daigaku.rb +27 -0
  10. data/lib/daigaku/chapter.rb +23 -0
  11. data/lib/daigaku/configuration.rb +86 -0
  12. data/lib/daigaku/course.rb +23 -0
  13. data/lib/daigaku/database.rb +64 -0
  14. data/lib/daigaku/exceptions.rb +19 -0
  15. data/lib/daigaku/generator.rb +53 -0
  16. data/lib/daigaku/loadable.rb +23 -0
  17. data/lib/daigaku/loading/chapters.rb +9 -0
  18. data/lib/daigaku/loading/courses.rb +9 -0
  19. data/lib/daigaku/loading/units.rb +9 -0
  20. data/lib/daigaku/reference_solution.rb +10 -0
  21. data/lib/daigaku/solution.rb +42 -0
  22. data/lib/daigaku/task.rb +10 -0
  23. data/lib/daigaku/terminal.rb +11 -0
  24. data/lib/daigaku/terminal/cli.rb +59 -0
  25. data/lib/daigaku/terminal/courses.rb +114 -0
  26. data/lib/daigaku/terminal/output.rb +72 -0
  27. data/lib/daigaku/terminal/setup.rb +115 -0
  28. data/lib/daigaku/terminal/solutions.rb +46 -0
  29. data/lib/daigaku/terminal/texts/about.txt +19 -0
  30. data/lib/daigaku/terminal/texts/courses_empty.txt +3 -0
  31. data/lib/daigaku/terminal/texts/hint_course_download.txt +13 -0
  32. data/lib/daigaku/terminal/texts/welcome.txt +12 -0
  33. data/lib/daigaku/terminal/welcome.rb +98 -0
  34. data/lib/daigaku/test.rb +46 -0
  35. data/lib/daigaku/test_result.rb +69 -0
  36. data/lib/daigaku/unit.rb +28 -0
  37. data/lib/daigaku/version.rb +3 -0
  38. data/lib/daigaku/views.rb +59 -0
  39. data/lib/daigaku/views/chapters_menu.rb +91 -0
  40. data/lib/daigaku/views/courses_menu.rb +87 -0
  41. data/lib/daigaku/views/main_menu.rb +37 -0
  42. data/lib/daigaku/views/splash.rb +57 -0
  43. data/lib/daigaku/views/task_view.rb +206 -0
  44. data/lib/daigaku/views/top_bar.rb +48 -0
  45. data/lib/daigaku/views/units_menu.rb +92 -0
  46. data/lib/daigaku/window.rb +160 -0
  47. data/spec/daigaku/chapter_spec.rb +76 -0
  48. data/spec/daigaku/configuration_spec.rb +161 -0
  49. data/spec/daigaku/course_spec.rb +75 -0
  50. data/spec/daigaku/database_spec.rb +79 -0
  51. data/spec/daigaku/generator_spec.rb +82 -0
  52. data/spec/daigaku/loading/chapters_spec.rb +16 -0
  53. data/spec/daigaku/loading/courses_spec.rb +16 -0
  54. data/spec/daigaku/loading/units_spec.rb +21 -0
  55. data/spec/daigaku/reference_solution_spec.rb +23 -0
  56. data/spec/daigaku/solution_spec.rb +79 -0
  57. data/spec/daigaku/task_spec.rb +23 -0
  58. data/spec/daigaku/terminal/cli_spec.rb +51 -0
  59. data/spec/daigaku/terminal/courses_spec.rb +60 -0
  60. data/spec/daigaku/terminal/output_spec.rb +123 -0
  61. data/spec/daigaku/terminal/setup_spec.rb +10 -0
  62. data/spec/daigaku/terminal/solutions_spec.rb +8 -0
  63. data/spec/daigaku/terminal/welcome_spec.rb +12 -0
  64. data/spec/daigaku/terminal_spec.rb +14 -0
  65. data/spec/daigaku/test_example_spec.rb +54 -0
  66. data/spec/daigaku/test_result_spec.rb +81 -0
  67. data/spec/daigaku/test_spec.rb +48 -0
  68. data/spec/daigaku/unit_spec.rb +85 -0
  69. data/spec/daigaku/views/chapters_menu_spec.rb +8 -0
  70. data/spec/daigaku/views/courses_menu_spec.rb +8 -0
  71. data/spec/daigaku/views/task_view_spec.rb +7 -0
  72. data/spec/daigaku/views/units_menu_spec.rb +8 -0
  73. data/spec/daigaku/views_spec.rb +23 -0
  74. data/spec/daigaku_spec.rb +57 -0
  75. data/spec/path_helpers_spec.rb +60 -0
  76. data/spec/resource_helpers_spec.rb +33 -0
  77. data/spec/spec_helper.rb +28 -0
  78. data/spec/support/macros/content_helpers.rb +129 -0
  79. data/spec/support/macros/mock_helpers.rb +20 -0
  80. data/spec/support/macros/path_helpers.rb +133 -0
  81. data/spec/support/macros/resource_helpers.rb +119 -0
  82. data/spec/support/macros/test_helpers.rb +6 -0
  83. metadata +361 -0
@@ -0,0 +1,119 @@
1
+ module ResourceHelpers
2
+ require 'fileutils'
3
+ require 'zip'
4
+
5
+ def prepare_courses
6
+ FileUtils.mkdir_p(courses_basepath) unless Dir.exist?(courses_basepath)
7
+
8
+ course_dir_names.each do |course|
9
+ chapter_dir_names.each do |chapter|
10
+ unit_dirs(course).each do |units|
11
+ units.each do |unit|
12
+ create_directory(unit)
13
+ create_file(unit, task_name, task_file_content)
14
+ create_file(unit, reference_solution_name, solution_content)
15
+ create_file(unit, test_name, test_content)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ def prepare_solutions
23
+ all_solution_file_paths.each do |path|
24
+ base_dir = File.dirname(path)
25
+ name = File.basename(path)
26
+ create_file(base_dir, name, solution_content)
27
+ end
28
+ end
29
+
30
+ def prepare_download(zip_file_name)
31
+ directory = File.dirname(course_dirs.first)
32
+ zip_file_path = File.join(File.dirname(directory), zip_file_name)
33
+
34
+ Zip::File.open(zip_file_path, Zip::File::CREATE) do |zip_file|
35
+ Dir[File.join(directory, '**', '**')].each do |file|
36
+ zip_file.add(file.sub(directory, '')[1..-1], file) { true }
37
+ end
38
+ end
39
+
40
+ File.read(zip_file_path)
41
+ end
42
+
43
+ def cleanup_download(zip_file_name)
44
+ directory = course_dirs.first
45
+ zip_file = File.join(File.dirname(directory), zip_file_name)
46
+ FileUtils.rm(zip_file) if File.exist?(zip_file)
47
+ end
48
+
49
+ def cleanup_temp_data
50
+ FileUtils.remove_dir(temp_basepath) if Dir.exist?(temp_basepath)
51
+ end
52
+
53
+ def create_directory(dir_path)
54
+ FileUtils.mkdir_p(dir_path) unless Dir.exist?(dir_path)
55
+ end
56
+
57
+ def create_file(base_dir, name, content)
58
+ create_directory(base_dir) unless Dir.exist?(base_dir)
59
+ file_path = File.join(base_dir, name)
60
+
61
+ if Dir.exist?(base_dir)
62
+ File.open(file_path, 'w') { |f| f.puts content }
63
+ end
64
+ end
65
+
66
+ def available_courses
67
+ course_dirs.map do |path|
68
+ Daigaku::Course.new(path)
69
+ end
70
+ end
71
+
72
+ def available_chapters(course_name)
73
+ chapter_dirs(course_name).map do |path|
74
+ Daigaku::Chapter.new(path)
75
+ end
76
+ end
77
+
78
+ def available_units(course_name, chapter_name)
79
+ units = unit_dirs(course_name).map do |units|
80
+ units.map do |path|
81
+ next unless path.split('/')[-2] == chapter_name
82
+ Daigaku::Unit.new(path)
83
+ end
84
+ end
85
+
86
+ units.map(&:compact).flatten
87
+ end
88
+
89
+ def available_task(course_name, chapter_name, unit_name)
90
+ task = unit_dirs(course_name).map do |units|
91
+ units.map do |path|
92
+ split = path.split('/')
93
+ next if (split[-2] != chapter_name || split[-1] != unit_name)
94
+
95
+ Daigaku::Task.new(path)
96
+ end
97
+ end
98
+
99
+ task.map(&:compact).flatten
100
+ end
101
+
102
+ def available_reference_solution(course_name, chapter_name, unit_name)
103
+ solution = unit_dirs(course_name).map do |units|
104
+ units.map do |path|
105
+ split = path.split('/')
106
+ next if (split[-2] != chapter_name || split[-1] != unit_name)
107
+
108
+ Daigaku::ReferenceSolution.new(path)
109
+ end
110
+ end
111
+
112
+ solution.map(&:compact).flatten
113
+ end
114
+
115
+ def available_solution(course_name, chapter_name, unit_name)
116
+ path = File.join(solutions_basepath, course_name, chapter_name, unit_name)
117
+ Daigaku::Solution.new(path)
118
+ end
119
+ end
@@ -0,0 +1,6 @@
1
+ module TestHelpers
2
+ include ContentHelpers
3
+ include PathHelpers
4
+ include ResourceHelpers
5
+ include MockHelpers
6
+ end
metadata ADDED
@@ -0,0 +1,361 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daigaku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Götze
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: curses
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '4.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '4.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '4.0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: thor
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 0.19.1
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: 0.19.1
87
+ - !ruby/object:Gem::Dependency
88
+ name: os
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: 0.9.6
94
+ type: :runtime
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 0.9.6
101
+ - !ruby/object:Gem::Dependency
102
+ name: colorize
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: 0.7.5
108
+ type: :runtime
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: 0.7.5
115
+ - !ruby/object:Gem::Dependency
116
+ name: rubyzip
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '1.0'
122
+ - - "<"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ type: :runtime
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ - - "<"
133
+ - !ruby/object:Gem::Version
134
+ version: '2.0'
135
+ - !ruby/object:Gem::Dependency
136
+ name: wisper
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: 2.0.0.rc1
142
+ - - "<"
143
+ - !ruby/object:Gem::Version
144
+ version: '3.0'
145
+ type: :runtime
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: 2.0.0.rc1
152
+ - - "<"
153
+ - !ruby/object:Gem::Version
154
+ version: '3.0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: bundler
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: '1.7'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - "~>"
167
+ - !ruby/object:Gem::Version
168
+ version: '1.7'
169
+ - !ruby/object:Gem::Dependency
170
+ name: rake
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - "~>"
174
+ - !ruby/object:Gem::Version
175
+ version: '10.0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - "~>"
181
+ - !ruby/object:Gem::Version
182
+ version: '10.0'
183
+ - !ruby/object:Gem::Dependency
184
+ name: webmock
185
+ requirement: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: 1.20.4
190
+ type: :development
191
+ prerelease: false
192
+ version_requirements: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - "~>"
195
+ - !ruby/object:Gem::Version
196
+ version: 1.20.4
197
+ - !ruby/object:Gem::Dependency
198
+ name: guard-rspec
199
+ requirement: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - "~>"
202
+ - !ruby/object:Gem::Version
203
+ version: 4.5.0
204
+ type: :development
205
+ prerelease: false
206
+ version_requirements: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - "~>"
209
+ - !ruby/object:Gem::Version
210
+ version: 4.5.0
211
+ description: Daigaku is the Japanese word for university. With Daigaku you can interactively
212
+ learn the Ruby Programming language using the command line.
213
+ email:
214
+ - paul.christoph.goetze@gmail.com
215
+ executables:
216
+ - daigaku
217
+ extensions: []
218
+ extra_rdoc_files: []
219
+ files:
220
+ - ".gitignore"
221
+ - Gemfile
222
+ - Guardfile
223
+ - README.md
224
+ - Rakefile
225
+ - bin/daigaku
226
+ - daigaku.gemspec
227
+ - lib/daigaku.rb
228
+ - lib/daigaku/chapter.rb
229
+ - lib/daigaku/configuration.rb
230
+ - lib/daigaku/course.rb
231
+ - lib/daigaku/database.rb
232
+ - lib/daigaku/exceptions.rb
233
+ - lib/daigaku/generator.rb
234
+ - lib/daigaku/loadable.rb
235
+ - lib/daigaku/loading/chapters.rb
236
+ - lib/daigaku/loading/courses.rb
237
+ - lib/daigaku/loading/units.rb
238
+ - lib/daigaku/reference_solution.rb
239
+ - lib/daigaku/solution.rb
240
+ - lib/daigaku/task.rb
241
+ - lib/daigaku/terminal.rb
242
+ - lib/daigaku/terminal/cli.rb
243
+ - lib/daigaku/terminal/courses.rb
244
+ - lib/daigaku/terminal/output.rb
245
+ - lib/daigaku/terminal/setup.rb
246
+ - lib/daigaku/terminal/solutions.rb
247
+ - lib/daigaku/terminal/texts/about.txt
248
+ - lib/daigaku/terminal/texts/courses_empty.txt
249
+ - lib/daigaku/terminal/texts/hint_course_download.txt
250
+ - lib/daigaku/terminal/texts/welcome.txt
251
+ - lib/daigaku/terminal/welcome.rb
252
+ - lib/daigaku/test.rb
253
+ - lib/daigaku/test_result.rb
254
+ - lib/daigaku/unit.rb
255
+ - lib/daigaku/version.rb
256
+ - lib/daigaku/views.rb
257
+ - lib/daigaku/views/chapters_menu.rb
258
+ - lib/daigaku/views/courses_menu.rb
259
+ - lib/daigaku/views/main_menu.rb
260
+ - lib/daigaku/views/splash.rb
261
+ - lib/daigaku/views/task_view.rb
262
+ - lib/daigaku/views/top_bar.rb
263
+ - lib/daigaku/views/units_menu.rb
264
+ - lib/daigaku/window.rb
265
+ - spec/daigaku/chapter_spec.rb
266
+ - spec/daigaku/configuration_spec.rb
267
+ - spec/daigaku/course_spec.rb
268
+ - spec/daigaku/database_spec.rb
269
+ - spec/daigaku/generator_spec.rb
270
+ - spec/daigaku/loading/chapters_spec.rb
271
+ - spec/daigaku/loading/courses_spec.rb
272
+ - spec/daigaku/loading/units_spec.rb
273
+ - spec/daigaku/reference_solution_spec.rb
274
+ - spec/daigaku/solution_spec.rb
275
+ - spec/daigaku/task_spec.rb
276
+ - spec/daigaku/terminal/cli_spec.rb
277
+ - spec/daigaku/terminal/courses_spec.rb
278
+ - spec/daigaku/terminal/output_spec.rb
279
+ - spec/daigaku/terminal/setup_spec.rb
280
+ - spec/daigaku/terminal/solutions_spec.rb
281
+ - spec/daigaku/terminal/welcome_spec.rb
282
+ - spec/daigaku/terminal_spec.rb
283
+ - spec/daigaku/test_example_spec.rb
284
+ - spec/daigaku/test_result_spec.rb
285
+ - spec/daigaku/test_spec.rb
286
+ - spec/daigaku/unit_spec.rb
287
+ - spec/daigaku/views/chapters_menu_spec.rb
288
+ - spec/daigaku/views/courses_menu_spec.rb
289
+ - spec/daigaku/views/task_view_spec.rb
290
+ - spec/daigaku/views/units_menu_spec.rb
291
+ - spec/daigaku/views_spec.rb
292
+ - spec/daigaku_spec.rb
293
+ - spec/path_helpers_spec.rb
294
+ - spec/resource_helpers_spec.rb
295
+ - spec/spec_helper.rb
296
+ - spec/support/macros/content_helpers.rb
297
+ - spec/support/macros/mock_helpers.rb
298
+ - spec/support/macros/path_helpers.rb
299
+ - spec/support/macros/resource_helpers.rb
300
+ - spec/support/macros/test_helpers.rb
301
+ homepage: https://github.com/daigaku-ruby/daigaku
302
+ licenses:
303
+ - MIT
304
+ metadata: {}
305
+ post_install_message:
306
+ rdoc_options: []
307
+ require_paths:
308
+ - lib
309
+ required_ruby_version: !ruby/object:Gem::Requirement
310
+ requirements:
311
+ - - ">="
312
+ - !ruby/object:Gem::Version
313
+ version: '0'
314
+ required_rubygems_version: !ruby/object:Gem::Requirement
315
+ requirements:
316
+ - - ">="
317
+ - !ruby/object:Gem::Version
318
+ version: '0'
319
+ requirements: []
320
+ rubyforge_project:
321
+ rubygems_version: 2.4.3
322
+ signing_key:
323
+ specification_version: 4
324
+ summary: Learning Ruby on the command line.
325
+ test_files:
326
+ - spec/daigaku/chapter_spec.rb
327
+ - spec/daigaku/configuration_spec.rb
328
+ - spec/daigaku/course_spec.rb
329
+ - spec/daigaku/database_spec.rb
330
+ - spec/daigaku/generator_spec.rb
331
+ - spec/daigaku/loading/chapters_spec.rb
332
+ - spec/daigaku/loading/courses_spec.rb
333
+ - spec/daigaku/loading/units_spec.rb
334
+ - spec/daigaku/reference_solution_spec.rb
335
+ - spec/daigaku/solution_spec.rb
336
+ - spec/daigaku/task_spec.rb
337
+ - spec/daigaku/terminal/cli_spec.rb
338
+ - spec/daigaku/terminal/courses_spec.rb
339
+ - spec/daigaku/terminal/output_spec.rb
340
+ - spec/daigaku/terminal/setup_spec.rb
341
+ - spec/daigaku/terminal/solutions_spec.rb
342
+ - spec/daigaku/terminal/welcome_spec.rb
343
+ - spec/daigaku/terminal_spec.rb
344
+ - spec/daigaku/test_example_spec.rb
345
+ - spec/daigaku/test_result_spec.rb
346
+ - spec/daigaku/test_spec.rb
347
+ - spec/daigaku/unit_spec.rb
348
+ - spec/daigaku/views/chapters_menu_spec.rb
349
+ - spec/daigaku/views/courses_menu_spec.rb
350
+ - spec/daigaku/views/task_view_spec.rb
351
+ - spec/daigaku/views/units_menu_spec.rb
352
+ - spec/daigaku/views_spec.rb
353
+ - spec/daigaku_spec.rb
354
+ - spec/path_helpers_spec.rb
355
+ - spec/resource_helpers_spec.rb
356
+ - spec/spec_helper.rb
357
+ - spec/support/macros/content_helpers.rb
358
+ - spec/support/macros/mock_helpers.rb
359
+ - spec/support/macros/path_helpers.rb
360
+ - spec/support/macros/resource_helpers.rb
361
+ - spec/support/macros/test_helpers.rb