asker-tool 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -19
  3. data/bin/asker +2 -1
  4. data/lib/asker/ai/ai.rb +10 -3
  5. data/lib/asker/ai/ai_calculate.rb +20 -6
  6. data/lib/asker/ai/code/base_code_ai.rb +104 -0
  7. data/lib/asker/{code/ai → ai/code}/code_ai_factory.rb +11 -1
  8. data/lib/asker/{code/ai → ai/code}/javascript_code_ai.rb +2 -5
  9. data/lib/asker/ai/code/problem_code_ai.rb +176 -0
  10. data/lib/asker/{code/ai → ai/code}/python_code_ai.rb +2 -5
  11. data/lib/asker/{code/ai → ai/code}/ruby_code_ai.rb +14 -7
  12. data/lib/asker/{code/ai → ai/code}/sql_code_ai.rb +2 -5
  13. data/lib/asker/ai/concept_ai.rb +12 -2
  14. data/lib/asker/ai/question.rb +28 -6
  15. data/lib/asker/ai/stages/base_stage.rb +45 -6
  16. data/lib/asker/ai/stages/stage_b.rb +100 -50
  17. data/lib/asker/ai/stages/stage_d.rb +75 -90
  18. data/lib/asker/ai/stages/stage_f.rb +64 -36
  19. data/lib/asker/ai/stages/stage_i.rb +79 -92
  20. data/lib/asker/ai/stages/stage_s.rb +41 -36
  21. data/lib/asker/ai/stages/stage_t.rb +149 -108
  22. data/lib/asker/application.rb +24 -7
  23. data/lib/asker/checker.rb +149 -52
  24. data/lib/asker/cli.rb +37 -32
  25. data/lib/asker/data/code.rb +76 -0
  26. data/lib/asker/data/column.rb +31 -21
  27. data/lib/asker/data/concept.rb +108 -65
  28. data/lib/asker/data/data_field.rb +14 -0
  29. data/lib/asker/data/row.rb +75 -52
  30. data/lib/asker/data/table.rb +91 -42
  31. data/lib/asker/data/template.rb +3 -1
  32. data/lib/asker/data/world.rb +61 -32
  33. data/lib/asker/{exporter/code_screen_exporter.rb → displayer/code_displayer.rb} +13 -6
  34. data/lib/asker/displayer/concept_ai_displayer.erb +10 -0
  35. data/lib/asker/displayer/concept_ai_displayer.rb +133 -0
  36. data/lib/asker/displayer/concept_displayer.rb +34 -0
  37. data/lib/asker/displayer/stats_displayer.rb +22 -0
  38. data/lib/asker/exporter/code_gift_exporter.rb +10 -11
  39. data/lib/asker/exporter/concept_ai_gift_exporter.rb +21 -13
  40. data/lib/asker/exporter/concept_ai_moodle_exporter.rb +44 -0
  41. data/lib/asker/exporter/concept_ai_yaml_exporter.rb +14 -9
  42. data/lib/asker/exporter/concept_doc_exporter.rb +21 -14
  43. data/lib/asker/exporter/data_gift_exporter.rb +29 -0
  44. data/lib/asker/exporter/output_file_exporter.rb +21 -0
  45. data/lib/asker/files/{config.ini → asker.ini} +48 -1
  46. data/lib/asker/files/example-concept.haml +24 -8
  47. data/lib/asker/files/language/du/connectors.yaml +81 -0
  48. data/lib/asker/files/language/du/mistakes.yaml +82 -0
  49. data/lib/asker/files/language/du/templates.yaml +29 -0
  50. data/lib/asker/files/language/en/connectors.yaml +44 -0
  51. data/lib/asker/files/language/en/mistakes.yaml +37 -0
  52. data/lib/asker/files/language/en/templates.yaml +29 -0
  53. data/lib/asker/files/language/es/connectors.yaml +92 -0
  54. data/lib/asker/files/language/es/mistakes.yaml +84 -0
  55. data/lib/asker/files/language/es/templates.yaml +29 -0
  56. data/lib/asker/files/language/fr/connectors.yaml +76 -0
  57. data/lib/asker/files/language/fr/mistakes.yaml +82 -0
  58. data/lib/asker/files/language/fr/templates.yaml +29 -0
  59. data/lib/asker/files/language/javascript/connectors.yaml +11 -0
  60. data/lib/asker/files/language/javascript/mistakes.yaml +30 -0
  61. data/lib/asker/files/language/javascript/templates.yaml +3 -0
  62. data/lib/asker/files/language/math/connectors.yaml +2 -0
  63. data/lib/asker/files/language/math/mistakes.yaml +2 -0
  64. data/lib/asker/files/language/math/templates.yaml +1 -0
  65. data/lib/asker/files/language/python/connectors.yaml +11 -0
  66. data/lib/asker/files/language/python/mistakes.yaml +26 -0
  67. data/lib/asker/files/language/python/templates.yaml +3 -0
  68. data/lib/asker/files/language/ruby/connectors.yaml +11 -0
  69. data/lib/asker/files/language/ruby/mistakes.yaml +33 -0
  70. data/lib/asker/files/language/ruby/templates.yaml +3 -0
  71. data/lib/asker/files/language/sql/connectors.yaml +6 -0
  72. data/lib/asker/files/language/sql/mistakes.yaml +11 -0
  73. data/lib/asker/files/language/sql/templates.yaml +2 -0
  74. data/lib/asker/formatter/concept_string_formatter.rb +13 -9
  75. data/lib/asker/formatter/moodle/matching.erb +38 -0
  76. data/lib/asker/formatter/moodle/multichoice.erb +49 -0
  77. data/lib/asker/formatter/moodle/shortanswer.erb +30 -0
  78. data/lib/asker/formatter/moodle/truefalse.erb +47 -0
  79. data/lib/asker/formatter/question_gift_formatter.rb +30 -20
  80. data/lib/asker/formatter/question_moodle_formatter.rb +27 -0
  81. data/lib/asker/lang/lang.rb +18 -12
  82. data/lib/asker/lang/lang_factory.rb +32 -5
  83. data/lib/asker/lang/text_actions.rb +87 -69
  84. data/lib/asker/loader/code_loader.rb +4 -4
  85. data/lib/asker/loader/content_loader.rb +16 -12
  86. data/lib/asker/loader/directory_loader.rb +3 -3
  87. data/lib/asker/loader/embedded_file.rb +42 -0
  88. data/lib/asker/loader/file_loader.rb +3 -12
  89. data/lib/asker/loader/haml_loader.rb +15 -0
  90. data/lib/asker/loader/image_url_loader.rb +9 -11
  91. data/lib/asker/loader/input_loader.rb +24 -8
  92. data/lib/asker/loader/project_loader.rb +42 -30
  93. data/lib/asker/logger.rb +30 -6
  94. data/lib/asker/project.rb +28 -117
  95. data/lib/asker/skeleton.rb +40 -29
  96. data/lib/asker.rb +68 -79
  97. metadata +57 -74
  98. data/docs/changelog/v2.1.md +0 -99
  99. data/docs/commands.md +0 -12
  100. data/docs/contributions.md +0 -18
  101. data/docs/history.md +0 -40
  102. data/docs/idea.md +0 -44
  103. data/docs/inputs/README.md +0 -39
  104. data/docs/inputs/code.md +0 -69
  105. data/docs/inputs/concepts.md +0 -142
  106. data/docs/inputs/jedi.md +0 -68
  107. data/docs/inputs/tables.md +0 -112
  108. data/docs/inputs/templates.md +0 -87
  109. data/docs/install/README.md +0 -38
  110. data/docs/install/manual.md +0 -26
  111. data/docs/install/scripts.md +0 -38
  112. data/docs/revise/asker-file.md +0 -41
  113. data/docs/revise/buenas-practicas/01-convocatoria.md +0 -30
  114. data/docs/revise/buenas-practicas/02-formulario.md +0 -35
  115. data/docs/revise/buenas-practicas/03-descripcion.md +0 -63
  116. data/docs/revise/buenas-practicas/04-resultados.md +0 -17
  117. data/docs/revise/buenas-practicas/05-reproducir.md +0 -10
  118. data/docs/revise/ejemplos/01/README.md +0 -27
  119. data/docs/revise/ejemplos/02/README.md +0 -31
  120. data/docs/revise/ejemplos/03/README.md +0 -31
  121. data/docs/revise/ejemplos/04/README.md +0 -37
  122. data/docs/revise/ejemplos/05/README.md +0 -25
  123. data/docs/revise/ejemplos/06/README.md +0 -43
  124. data/docs/revise/ejemplos/README.md +0 -11
  125. data/docs/revise/projects.md +0 -74
  126. data/lib/asker/code/ai/base_code_ai.rb +0 -48
  127. data/lib/asker/code/code.rb +0 -53
  128. data/lib/asker/exporter/concept_ai_screen_exporter.rb +0 -115
  129. data/lib/asker/exporter/concept_screen_exporter.rb +0 -25
  130. data/lib/asker/exporter/main.rb +0 -9
data/lib/asker/checker.rb CHANGED
@@ -1,29 +1,46 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require 'rainbow'
3
4
 
5
+ ##
6
+ # Check HAML file syntax
4
7
  module Checker
8
+ ##
9
+ # Check:
10
+ # * file exist
11
+ # * filename extension
12
+ # * and HAML syntax
13
+ # @param filepath (String)
5
14
  def self.check(filepath)
6
15
  unless File.exist? filepath
7
- puts Rainbow("File not found!").red.bright
16
+ puts Rainbow('File not found!').red.bright
8
17
  return false
9
18
  end
10
19
  unless File.extname(filepath) == '.haml'
11
- puts Rainbow("Only check HAML files!").yellow.bright
20
+ puts Rainbow('Only check HAML files!').yellow.bright
12
21
  return false
13
22
  end
14
23
  check_filepath(filepath)
15
24
  end
16
25
 
26
+ ##
27
+ # Check HAML syntax
28
+ # @param filepath (String)
17
29
  def self.check_filepath(filepath)
18
30
  data = Data.new(filepath)
19
31
  data.check
20
32
  data.show_errors
21
- data.is_ok?
33
+ data.ok?
22
34
  end
23
35
 
36
+ ##
37
+ # Internal class that revise syntax
38
+ # rubocop:disable Metrics/ClassLength
24
39
  class Data
25
40
  attr_reader :inputs
26
41
  attr_reader :outputs
42
+
43
+ # rubocop:disable Metrics/MethodLength
27
44
  def initialize(filepath)
28
45
  @inputs = File.read(filepath).split("\n")
29
46
  @outputs = []
@@ -38,8 +55,9 @@ module Checker
38
55
  end
39
56
  @ok = false
40
57
  end
58
+ # rubocop:enable Metrics/MethodLength
41
59
 
42
- def is_ok?
60
+ def ok?
43
61
  @ok
44
62
  end
45
63
 
@@ -49,18 +67,33 @@ module Checker
49
67
  end
50
68
  end
51
69
 
70
+ # rubocop:disable Metrics/AbcSize
71
+ # rubocop:disable Metrics/MethodLength
52
72
  def show_errors
53
73
  errors = 0
74
+ # puts "Line : Error description"
54
75
  @outputs.each do |i|
55
76
  next if i[:state] == :ok
77
+
56
78
  errors += 1
57
- puts "%02d" % i[:id] + ": %s." % i[:msg] + " => #{i[:source][0,40]}" if errors < 11
58
- puts "..." if errors == 11
79
+ if errors < 11
80
+ data = { id: i[:id], msg: i[:msg], source: i[:source][0, 40] }
81
+ puts format(' %<id>03d : %<msg>s. => %<source>s', data)
82
+ end
83
+ puts '...' if errors == 11
84
+ end
85
+
86
+ if errors.positive?
87
+ puts Rainbow("[ERROR] #{errors} errors " \
88
+ "from #{@inputs.size} lines!").red.bright
59
89
  end
60
- puts Rainbow("[ERROR] #{errors} errors from #{@inputs.size} lines!").red.bright if errors > 0
61
- puts Rainbow("Syntax OK!").green if errors == 0
90
+ puts Rainbow('Syntax OK!').green if errors.zero?
62
91
  end
92
+ # rubocop:enable Metrics/AbcSize
93
+ # rubocop:enable Metrics/MethodLength
63
94
 
95
+ # rubocop:disable Metrics/MethodLength
96
+ # rubocop:disable Metrics/AbcSize
64
97
  def check
65
98
  @ok = true
66
99
  @inputs.each_with_index do |line, index|
@@ -84,31 +117,41 @@ module Checker
84
117
  end
85
118
  @ok
86
119
  end
120
+ # rubocop:enable Metrics/MethodLength
121
+ # rubocop:enable Metrics/AbcSize
122
+
123
+ private
87
124
 
88
125
  def check_empty_lines(line, index)
89
- if line.strip.size.zero? or line.start_with? '#'
90
- @outputs[index][:type] = :empty
91
- @outputs[index][:level] = -1
92
- @outputs[index][:state] = :ok
93
- end
126
+ return unless line.strip.size.zero? || line.start_with?('#')
127
+
128
+ @outputs[index][:type] = :empty
129
+ @outputs[index][:level] = -1
130
+ @outputs[index][:state] = :ok
94
131
  end
95
132
 
133
+ # rubocop:disable Metrics/MethodLength
134
+ # rubocop:disable Metrics/AbcSize
96
135
  def check_map(line, index)
97
- if index == 0
136
+ if index.zero?
98
137
  @outputs[index][:type] = :map
99
138
  if line.start_with?('%map{')
100
139
  @outputs[index][:state] = :ok
101
140
  else
102
141
  @outputs[index][:state] = :err
103
- @outputs[index][:msg] = "Start with '%map{'"
142
+ @outputs[index][:msg] = 'Start with %map{'
104
143
  end
105
- elsif index > 0 and line.include?('%map{')
144
+ elsif index.positive? && line.include?('%map{')
106
145
  @outputs[index][:state] = :err
107
146
  @outputs[index][:type] = :map
108
- @outputs[index][:msg] = "Write '%map' on line 0"
147
+ @outputs[index][:msg] = 'Write %map on line 0'
109
148
  end
110
149
  end
150
+ # rubocop:enable Metrics/MethodLength
151
+ # rubocop:enable Metrics/AbcSize
111
152
 
153
+ # rubocop:disable Metrics/MethodLength
154
+ # rubocop:disable Metrics/AbcSize
112
155
  def check_concept(line, index)
113
156
  return unless @outputs[index][:state] == :none
114
157
  return unless line.include? '%concept'
@@ -124,7 +167,11 @@ module Checker
124
167
  @outputs[index][:msg] = 'Write 2 spaces before %concept'
125
168
  end
126
169
  end
170
+ # rubocop:enable Metrics/MethodLength
171
+ # rubocop:enable Metrics/AbcSize
127
172
 
173
+ # rubocop:disable Metrics/AbcSize
174
+ # rubocop:disable Metrics/MethodLength
128
175
  def check_names(line, index)
129
176
  return unless @outputs[index][:state] == :none
130
177
  return unless line.include? '%names'
@@ -135,12 +182,16 @@ module Checker
135
182
  if find_parent(index) != :concept
136
183
  @outputs[index][:state] = :err
137
184
  @outputs[index][:msg] = 'Parent(concept) not found!'
138
- elsif not line.start_with? ' %names'
185
+ elsif !line.start_with? ' %names'
139
186
  @outputs[index][:state] = :err
140
- @outputs[index][:msg] = "Write 4 spaces before %names"
187
+ @outputs[index][:msg] = 'Write 4 spaces before %names'
141
188
  end
142
189
  end
190
+ # rubocop:enable Metrics/AbcSize
191
+ # rubocop:enable Metrics/MethodLength
143
192
 
193
+ # rubocop:disable Metrics/AbcSize
194
+ # rubocop:disable Metrics/MethodLength
144
195
  def check_tags(line, index)
145
196
  return unless @outputs[index][:state] == :none
146
197
  return unless line.include? '%tags'
@@ -151,12 +202,16 @@ module Checker
151
202
  if find_parent(index) != :concept
152
203
  @outputs[index][:state] = :err
153
204
  @outputs[index][:msg] = 'Parent(concept) not found!'
154
- elsif not line.start_with? ' %tags'
205
+ elsif !line.start_with? ' %tags'
155
206
  @outputs[index][:state] = :err
156
- @outputs[index][:msg] = "Write 4 spaces before %tags"
207
+ @outputs[index][:msg] = 'Write 4 spaces before %tags'
157
208
  end
158
209
  end
210
+ # rubocop:enable Metrics/AbcSize
211
+ # rubocop:enable Metrics/MethodLength
159
212
 
213
+ # rubocop:disable Metrics/AbcSize
214
+ # rubocop:disable Metrics/MethodLength
160
215
  def check_def(line, index)
161
216
  return unless @outputs[index][:state] == :none
162
217
  return unless line.include? '%def'
@@ -167,12 +222,16 @@ module Checker
167
222
  if find_parent(index) != :concept
168
223
  @outputs[index][:state] = :err
169
224
  @outputs[index][:msg] = 'Parent(concept) not found!'
170
- elsif not line.start_with? ' %def'
225
+ elsif !line.start_with? ' %def'
171
226
  @outputs[index][:state] = :err
172
- @outputs[index][:msg] = "Write 4 spaces before %def"
227
+ @outputs[index][:msg] = 'Write 4 spaces before %def'
173
228
  end
174
229
  end
230
+ # rubocop:enable Metrics/AbcSize
231
+ # rubocop:enable Metrics/MethodLength
175
232
 
233
+ # rubocop:disable Metrics/AbcSize
234
+ # rubocop:disable Metrics/MethodLength
176
235
  def check_table(line, index)
177
236
  return unless @outputs[index][:state] == :none
178
237
  return unless line.include? '%table'
@@ -183,12 +242,16 @@ module Checker
183
242
  if find_parent(index) != :concept
184
243
  @outputs[index][:state] = :err
185
244
  @outputs[index][:msg] = 'Parent(concept) not found!'
186
- elsif not line.start_with? ' %table'
245
+ elsif !line.start_with? ' %table'
187
246
  @outputs[index][:state] = :err
188
- @outputs[index][:msg] = "Write 4 spaces before %table"
247
+ @outputs[index][:msg] = 'Write 4 spaces before %table'
189
248
  end
190
249
  end
250
+ # rubocop:enable Metrics/AbcSize
251
+ # rubocop:enable Metrics/MethodLength
191
252
 
253
+ # rubocop:disable Metrics/AbcSize
254
+ # rubocop:disable Metrics/MethodLength
192
255
  def check_row(line, index)
193
256
  return unless @outputs[index][:state] == :none
194
257
  return unless line.include? '%row'
@@ -199,7 +262,7 @@ module Checker
199
262
  if count_spaces(line) == 6
200
263
  @outputs[index][:level] = 3
201
264
  parent = find_parent(index)
202
- unless [:table, :features].include? parent
265
+ unless %i[table features].include? parent
203
266
  @outputs[index][:state] = :err
204
267
  @outputs[index][:msg] = 'Parent(table/features) not found!'
205
268
  end
@@ -211,10 +274,14 @@ module Checker
211
274
  end
212
275
  else
213
276
  @outputs[index][:state] = :err
214
- @outputs[index][:msg] = "Write 6 or 8 spaces before %row"
277
+ @outputs[index][:msg] = 'Write 6 or 8 spaces before %row'
215
278
  end
216
279
  end
280
+ # rubocop:enable Metrics/AbcSize
281
+ # rubocop:enable Metrics/MethodLength
217
282
 
283
+ # rubocop:disable Metrics/AbcSize
284
+ # rubocop:disable Metrics/MethodLength
218
285
  def check_col(line, index)
219
286
  return unless @outputs[index][:state] == :none
220
287
  return unless line.include? '%col'
@@ -235,10 +302,28 @@ module Checker
235
302
  end
236
303
  else
237
304
  @outputs[index][:state] = :err
238
- @outputs[index][:msg] = "Write 8 or 10 spaces before %col"
305
+ @outputs[index][:msg] = 'Write 8 or 10 spaces before %col'
239
306
  end
307
+ check_text(line, index)
240
308
  end
309
+ # rubocop:enable Metrics/AbcSize
310
+ # rubocop:enable Metrics/MethodLength
241
311
 
312
+ def check_text(line, index)
313
+ return unless @outputs[index][:state] == :ok
314
+
315
+ ok = ''
316
+ %w[< >].each do |char|
317
+ ok = char if line.include? char
318
+ end
319
+ return if ok == ''
320
+
321
+ @outputs[index][:state] = :err
322
+ @outputs[index][:msg] = "Char #{ok} not allow!"
323
+ end
324
+
325
+ # rubocop:disable Metrics/MethodLength
326
+ # rubocop:disable Metrics/AbcSize
242
327
  def check_template(line, index)
243
328
  return unless @outputs[index][:state] == :none
244
329
  return unless line.include? '%template'
@@ -249,12 +334,16 @@ module Checker
249
334
  if find_parent(index) != :table
250
335
  @outputs[index][:state] = :err
251
336
  @outputs[index][:msg] = 'Parent(concept) not found!'
252
- elsif not line.start_with? ' %template'
337
+ elsif !line.start_with? ' %template'
253
338
  @outputs[index][:state] = :err
254
- @outputs[index][:msg] = "Write 6 spaces before %template"
339
+ @outputs[index][:msg] = 'Write 6 spaces before %template'
255
340
  end
256
341
  end
342
+ # rubocop:enable Metrics/AbcSize
343
+ # rubocop:enable Metrics/MethodLength
257
344
 
345
+ # rubocop:disable Metrics/MethodLength
346
+ # rubocop:disable Metrics/AbcSize
258
347
  def check_code(line, index)
259
348
  return unless @outputs[index][:state] == :none
260
349
  return unless line.include? '%code'
@@ -270,7 +359,11 @@ module Checker
270
359
  @outputs[index][:msg] = 'Write 2 spaces before %code'
271
360
  end
272
361
  end
362
+ # rubocop:enable Metrics/MethodLength
363
+ # rubocop:enable Metrics/AbcSize
273
364
 
365
+ # rubocop:disable Metrics/MethodLength
366
+ # rubocop:disable Metrics/AbcSize
274
367
  def check_type(line, index)
275
368
  return unless @outputs[index][:state] == :none
276
369
  return unless line.include? '%type'
@@ -281,12 +374,16 @@ module Checker
281
374
  if find_parent(index) != :code
282
375
  @outputs[index][:state] = :err
283
376
  @outputs[index][:msg] = 'Parent(code) not found!'
284
- elsif not line.start_with? ' %type'
377
+ elsif !line.start_with? ' %type'
285
378
  @outputs[index][:state] = :err
286
- @outputs[index][:msg] = "Write 4 spaces before %type"
379
+ @outputs[index][:msg] = 'Write 4 spaces before %type'
287
380
  end
288
381
  end
382
+ # rubocop:enable Metrics/AbcSize
383
+ # rubocop:enable Metrics/MethodLength
289
384
 
385
+ # rubocop:disable Metrics/MethodLength
386
+ # rubocop:disable Metrics/AbcSize
290
387
  def check_path(line, index)
291
388
  return unless @outputs[index][:state] == :none
292
389
  return unless line.include? '%path'
@@ -297,12 +394,16 @@ module Checker
297
394
  if find_parent(index) != :code
298
395
  @outputs[index][:state] = :err
299
396
  @outputs[index][:msg] = 'Parent(code) not found!'
300
- elsif not line.start_with? ' %path'
397
+ elsif !line.start_with? ' %path'
301
398
  @outputs[index][:state] = :err
302
- @outputs[index][:msg] = "Write 4 spaces before %type"
399
+ @outputs[index][:msg] = 'Write 4 spaces before %type'
303
400
  end
304
401
  end
402
+ # rubocop:enable Metrics/AbcSize
403
+ # rubocop:enable Metrics/MethodLength
305
404
 
405
+ # rubocop:disable Metrics/MethodLength
406
+ # rubocop:disable Metrics/AbcSize
306
407
  def check_features(line, index)
307
408
  return unless @outputs[index][:state] == :none
308
409
  return unless line.include? '%features'
@@ -313,16 +414,19 @@ module Checker
313
414
  if find_parent(index) != :code
314
415
  @outputs[index][:state] = :err
315
416
  @outputs[index][:msg] = 'Parent(code) not found!'
316
- elsif not line.start_with? ' %features'
417
+ elsif !line.start_with? ' %features'
317
418
  @outputs[index][:state] = :err
318
- @outputs[index][:msg] = "Write 4 spaces before %features"
419
+ @outputs[index][:msg] = 'Write 4 spaces before %features'
319
420
  end
320
421
  end
422
+ # rubocop:enable Metrics/AbcSize
423
+ # rubocop:enable Metrics/MethodLength
321
424
 
322
425
  def check_unknown(line, index)
323
426
  return unless @outputs[index][:state] == :none
427
+
324
428
  @outputs[index][:type] = :unknown
325
- @outputs[index][:level] = count_spaces(line)/2
429
+ @outputs[index][:level] = count_spaces(line) / 2
326
430
  @outputs[index][:state] = :err
327
431
  @outputs[index][:msg] = "Unknown tag with parent(#{find_parent(index)})!"
328
432
  end
@@ -330,27 +434,20 @@ module Checker
330
434
  def find_parent(index)
331
435
  current_level = @outputs[index][:level]
332
436
  return :noparent if current_level.zero?
437
+
333
438
  i = index - 1
334
- while(i >= 0)
439
+ while i >= 0
335
440
  return @outputs[i][:type] if @outputs[i][:level] == current_level - 1
336
- i = i - 1
441
+
442
+ i -= 1
337
443
  end
338
- return :noparent
444
+ :noparent
339
445
  end
340
446
 
341
447
  def count_spaces(line)
342
- return 0 if line.start_with? '%'
343
- return 1 if line.start_with? ' %'
344
- return 2 if line.start_with? ' %'
345
- return 3 if line.start_with? ' %'
346
- return 4 if line.start_with? ' %'
347
- return 5 if line.start_with? ' %'
348
- return 6 if line.start_with? ' %'
349
- return 7 if line.start_with? ' %'
350
- return 8 if line.start_with? ' %'
351
- return 9 if line.start_with? ' %'
352
- return 10 if line.start_with? ' %'
353
- return -1
448
+ a = line.split('%')
449
+ a[0].count(' ')
354
450
  end
355
451
  end
452
+ # rubocop:enable Metrics/ClassLength
356
453
  end
data/lib/asker/cli.rb CHANGED
@@ -15,52 +15,32 @@ class CLI < Thor
15
15
  ##
16
16
  # Show current version
17
17
  def version
18
- print Rainbow(Application::NAME).bright.blue
19
- puts " (version #{Rainbow(Application::VERSION).green})"
18
+ puts "#{Application::NAME} version #{Application::VERSION}"
20
19
  end
21
20
 
22
21
  map ['f', '-f', '--file'] => 'file'
23
22
  desc 'file NAME', 'Build output files, from HAML/XML input file.'
24
- option :color, type: :boolean
25
23
  long_desc <<-LONGDESC
26
- Create output files, from input file (HAML/XML format).
27
24
 
28
25
  Build questions about contents defined into input file specified.
29
26
 
30
- Examples:
27
+ Create output files, from input file (HAML/XML format).
31
28
 
32
- (1) #{Rainbow('asker input/foo/foo.haml').yellow}, Build questions from HAML file.
29
+ Examples:
33
30
 
34
- (2) #{Rainbow('asker input/foo/foo.xml').yellow}, Build questions from XML file.
31
+ (1) #{Rainbow('asker input/foo/foo.haml').aqua}, Build questions from HAML file.
35
32
 
36
- (3) #{Rainbow('asker file --no-color input/foo/foo.haml').yellow}, Same as (1) but without colors.
33
+ (2) #{Rainbow('asker input/foo/foo.xml').aqua}, Build questions from XML file.
37
34
 
38
- (4) #{Rainbow('asker projects/foo/foo.yaml').yellow}, Build questions from YAML project file.
35
+ (3) #{Rainbow('asker projects/foo/foo.yaml').aqua}, Build questions from YAML project file.
39
36
 
40
37
  LONGDESC
41
38
  ##
42
39
  # Create questions from input file
43
40
  # @param filename (String) Path to input file
44
41
  def file(filename)
45
- # Enable/disable color output
46
- Rainbow.enabled = false if options['color'] == false
47
42
  # Asker start processing input file
48
- Asker.new.start(filename)
49
- end
50
-
51
- map ['i', '-i', '--init'] => 'init'
52
- desc 'init', 'Create default INI config fie'
53
- ##
54
- # Create default INI config file
55
- def init
56
- src = File.join(File.dirname(__FILE__), 'files', 'config.ini')
57
- dst = File.join(Dir.pwd, 'config.ini')
58
- if File.exist? dst
59
- puts "[WARN] Exists file! => #{Rainbow(File.basename(dst)).yellow.bright}"
60
- else
61
- FileUtils.cp(src, dst)
62
- puts "[ OK ] Create file => #{Rainbow(File.basename(dst)).green}"
63
- end
43
+ Asker.start(filename)
64
44
  end
65
45
 
66
46
  map ['c', '-c', '--check'] => 'check'
@@ -75,14 +55,29 @@ class CLI < Thor
75
55
  Asker.check(filename)
76
56
  end
77
57
 
78
- map ['n', '-b', '--new', 'new'] => 'create_skeleton'
79
- desc 'new', 'Create Asker demo input files'
58
+ map ['h', '-h', '--homepage', 'homepage'] => 'show_homepage'
59
+ desc 'homepage', 'Documentation homepage'
60
+ ##
61
+ # Show documentation homepage
62
+ def show_homepage()
63
+ puts Application::HOMEPAGE
64
+ end
65
+
66
+ map ['i', '-i', '--init'] => 'init'
67
+ desc 'init', 'Create default INI config file'
68
+ ##
69
+ # Create default INI config file
70
+ def init
71
+ Asker.create_configuration
72
+ end
73
+
74
+ map ['n', '-n', '--new', 'new'] => 'create_input'
75
+ desc 'new [FOLDER]', 'Create Asker demo input files'
80
76
  ##
81
77
  # Create Asker demo input files
82
78
  # @param dirname (String) Path to folder
83
- def create_skeleton(dirname)
84
- # Asker start processing input file
85
- Asker.create_skeleton(dirname)
79
+ def create_input(dirname)
80
+ Asker.create_input(dirname)
86
81
  end
87
82
 
88
83
  ##
@@ -92,4 +87,14 @@ class CLI < Thor
92
87
  def method_missing(method, *_args, &_block)
93
88
  file(method.to_s)
94
89
  end
90
+
91
+ def respond_to_missing?(_method_name)
92
+ true
93
+ end
94
+
95
+ ##
96
+ # Thor stop and show messages on screen on failure
97
+ def self.exit_on_failure?
98
+ true
99
+ end
95
100
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../ai/code/code_ai_factory'
4
+ require_relative '../project'
5
+ require_relative '../logger'
6
+ require_relative '../formatter/code_string_formatter'
7
+
8
+ ##
9
+ # Code data object
10
+ class Code
11
+ attr_reader :dirname, :filename, :type
12
+ attr_accessor :process, :features
13
+ attr_reader :lines, :questions
14
+
15
+ ##
16
+ # Initialize Code object
17
+ # @param dirname (String)
18
+ # @param filename (String)
19
+ # @param type (String)
20
+ def initialize(dirname, filename, type)
21
+ @dirname = dirname
22
+ @filename = filename
23
+ @type = type
24
+ @filepath = File.join(@dirname, @filename)
25
+ @process = false
26
+ @features = []
27
+ @lines = load(@filepath)
28
+ @questions = []
29
+ end
30
+
31
+ def process?
32
+ @process
33
+ end
34
+
35
+ def lines_to_s(lines)
36
+ out = ''
37
+ lines.each_with_index do |line, index|
38
+ out << format("%2d| #{line}\n", (index + 1))
39
+ end
40
+ out
41
+ end
42
+
43
+ def debug
44
+ Logger.verbose CodeStringFormatter.to_s(self)
45
+ end
46
+
47
+ private
48
+
49
+ def load(filepath)
50
+ return if filepath.nil?
51
+
52
+ unless File.exist? filepath
53
+ Logger.verboseln Rainbow("[ERROR] Unkown file #{filepath}").red.bright
54
+ return
55
+ end
56
+ content = File.read(filepath)
57
+ encode_and_split(content)
58
+ end
59
+
60
+ def encode_and_split(text, encoding = :default)
61
+ # Convert text to UTF-8 deleting unknown chars
62
+ text ||= '' # Ensure text is not nil
63
+ flag = [:default, 'UTF-8'].include? encoding
64
+ return text.encode('UTF-8', invalid: :replace).split("\n") if flag
65
+
66
+ # Convert text from input ENCODING to UTF-8
67
+ ec = Encoding::Converter.new(encoding.to_s, 'UTF-8')
68
+ begin
69
+ text = ec.convert(text)
70
+ rescue StandardError => e
71
+ puts "[ERROR] Encoding: #{e}"
72
+ end
73
+
74
+ text.split("\n")
75
+ end
76
+ end
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # encoding: utf-8
3
2
 
4
3
  # Contain data information for every column
5
4
  # Params:
@@ -9,10 +8,15 @@
9
8
  class Column
10
9
  attr_reader :row, :index, :id, :raw, :lang, :type, :simple
11
10
 
11
+ ##
12
+ # initialize Column
13
+ # @param row (Row)
14
+ # @param index (Integer)
15
+ # @param xml_data (XMLdata)
12
16
  def initialize(row, index, xml_data)
13
17
  @row = row
14
18
  @index = index
15
- @id = @row.id + '.' + @index.to_s
19
+ @id = "#{@row.id}.#{@index}"
16
20
  @raw = ''
17
21
  @lang = @row.langs[@index]
18
22
  @type = @row.types[@index]
@@ -28,35 +32,41 @@ class Column
28
32
  return "<img src=\"#{raw}\" alt\=\"image\">"
29
33
  when 'textfile_path'
30
34
  return "<pre>#{raw}</pre>"
31
- else
32
- return "ERROR type #{@type}"
33
35
  end
36
+ "ERROR type #{@type}"
34
37
  end
35
38
 
36
39
  private
37
40
 
38
41
  def read_data_from_xml(xml_data)
39
- raise '[ERROR] Column XML data with elements!' if xml_data.elements.count.positive?
42
+ raise '[ERROR] Column with elements!' if xml_data.elements.count.positive?
40
43
 
41
44
  @raw = xml_data.text.strip.to_s
42
45
 
43
46
  # read attributes from XML input data
44
- if xml_data.attributes['lang']
45
- code = xml_data.attributes['lang'].strip
46
- if code != @lang.code
47
- @lang = LangFactory.instance.get(code)
48
- @simple[:lang] = false
49
- @row.simple_off(:lang)
50
- end
51
- end
47
+ read_lang_from_xml(xml_data)
48
+ read_type_from_xml(xml_data)
49
+ end
52
50
 
53
- if xml_data.attributes['type']
54
- type = xml_data.attributes['type'].strip
55
- if type != @type.to_s
56
- @type = type
57
- @simple[:type] = false
58
- @row.simple_off(:type)
59
- end
60
- end
51
+ def read_lang_from_xml(xml_data)
52
+ return unless xml_data.attributes['lang']
53
+
54
+ code = xml_data.attributes['lang'].strip
55
+ return if code == @lang.code
56
+
57
+ @lang = LangFactory.instance.get(code)
58
+ @simple[:lang] = false
59
+ @row.simple_off(:lang)
60
+ end
61
+
62
+ def read_type_from_xml(xml_data)
63
+ return unless xml_data.attributes['type']
64
+
65
+ type = xml_data.attributes['type'].strip
66
+ return if type == @type.to_s
67
+
68
+ @type = type
69
+ @simple[:type] = false
70
+ @row.simple_off(:type)
61
71
  end
62
72
  end