asker-tool 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/asker/ai/stages/stage_b.rb +1 -10
- data/lib/asker/ai/stages/stage_d.rb +4 -10
- data/lib/asker/ai/stages/stage_f.rb +1 -20
- data/lib/asker/application.rb +1 -1
- data/lib/asker/check_input/input_data.rb +358 -0
- data/lib/asker/check_input.rb +51 -0
- data/lib/asker/loader/content_loader.rb +3 -3
- data/lib/asker.rb +2 -3
- metadata +32 -3
- data/lib/asker/input_checker.rb +0 -450
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0ce9d640d7af95956ae17f28a2acdffba7ca6f31437fbf7d18b6de30d5fd73a
|
4
|
+
data.tar.gz: d62bc1fd0380f141dda9e17bd11beb24da62b99be7b4eed13e5206c265589f52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f35ecee5e80950d66c57b039e39d9be4eb1a06b87b9fc6ca19b0cc2fa8ca99769467fba7608c55e8d1a1e408e17088723c014d8b677fad506896669e65060f1
|
7
|
+
data.tar.gz: 99b0da9a849a8d78802f70b03046d98df35f936086dd2f1eeca86a3655c5b8d5b1bbd5c221c291b19db5fafc802fd6202fb117ad8dd78f2f0fd57c907d98213d
|
data/README.md
CHANGED
@@ -5,16 +5,13 @@ require 'set'
|
|
5
5
|
require_relative 'base_stage'
|
6
6
|
require_relative '../question'
|
7
7
|
|
8
|
-
##
|
9
|
-
# range b1
|
10
8
|
class StageB < BaseStage
|
11
9
|
##
|
10
|
+
# range b1
|
12
11
|
# Process table data to generate match questions
|
13
12
|
# @param table (Table)
|
14
13
|
# @param list1 (Array) Rows that belong to this table
|
15
14
|
# @param list2 (Array) List with similar rows (same table name) from the neighbours tables
|
16
|
-
# rubocop:disable Metrics/AbcSize
|
17
|
-
# rubocop:disable Metrics/MethodLength
|
18
15
|
def run(table, list1, list2)
|
19
16
|
questions = []
|
20
17
|
return questions if table.fields.count < 2
|
@@ -44,12 +41,6 @@ class StageB < BaseStage
|
|
44
41
|
# @param list2 (Array) List with similar rows (same table name) from the neighbours tables
|
45
42
|
# @param index1 (Integer) Use this field number
|
46
43
|
# @param index2 (Integer) Use this field number
|
47
|
-
# rubocop:disable Metrics/AbcSize
|
48
|
-
# rubocop:disable Metrics/MethodLength
|
49
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
50
|
-
# rubocop:disable Style/ConditionalAssignment
|
51
|
-
# rubocop:disable Metrics/BlockLength
|
52
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
53
44
|
def process_table_match2fields(p_table, list1, list2, index1, index2)
|
54
45
|
questions = []
|
55
46
|
lang = concept.lang
|
@@ -7,12 +7,6 @@ require_relative '../question'
|
|
7
7
|
|
8
8
|
# range d1-d4
|
9
9
|
class StageD < BaseStage
|
10
|
-
# rubocop:disable Lint/BooleanSymbol
|
11
|
-
# rubocop:disable Metrics/MethodLength
|
12
|
-
# rubocop:disable Metrics/AbcSize
|
13
|
-
# rubocop:disable Metrics/BlockLength
|
14
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
15
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
16
10
|
def run
|
17
11
|
# Stage D: process every definition, I mean every <def> tag
|
18
12
|
questions = []
|
@@ -67,22 +61,22 @@ class StageD < BaseStage
|
|
67
61
|
|
68
62
|
# Question choice => mispelled
|
69
63
|
q = Question.new(:choice)
|
70
|
-
q.name = "#{name(:id)}-#{num}-d2def-
|
64
|
+
q.name = "#{name(:id)}-#{num}-d2def-misspelled"
|
71
65
|
q.text = random_image_for(name(:raw)) + lang.text_for(:d2, name(:decorated), lang.do_mistake_to(t))
|
72
66
|
q.good = lang.text_for(:misspelling)
|
73
67
|
q.bads << lang.text_for(:true)
|
74
68
|
q.bads << lang.text_for(:false)
|
75
|
-
q.feedback = "Definition text
|
69
|
+
q.feedback = "Definition text misspelled!: #{t}"
|
76
70
|
questions << q
|
77
71
|
|
78
72
|
# Question choice => name mispelled
|
79
73
|
q = Question.new(:choice)
|
80
|
-
q.name = "#{name(:id)}-#{num}-d2name-
|
74
|
+
q.name = "#{name(:id)}-#{num}-d2name-misspelled"
|
81
75
|
q.text = random_image_for(name(:raw)) + lang.text_for(:d2, lang.do_mistake_to(name(:raw)), t)
|
82
76
|
q.good = lang.text_for(:misspelling)
|
83
77
|
q.bads << lang.text_for(:true)
|
84
78
|
q.bads << lang.text_for(:false)
|
85
|
-
q.feedback = "Concept name
|
79
|
+
q.feedback = "Concept name misspelled!: #{name(:raw)}"
|
86
80
|
questions << q
|
87
81
|
|
88
82
|
# Question choice => true
|
@@ -3,8 +3,6 @@
|
|
3
3
|
require_relative 'base_stage'
|
4
4
|
require_relative '../question'
|
5
5
|
|
6
|
-
# StageF: process tables with 1 field
|
7
|
-
# rubocop:disable Metrics/ClassLength
|
8
6
|
class StageF < BaseStage
|
9
7
|
##
|
10
8
|
# run stage_f: generate guqestion for tables with 1 field
|
@@ -24,8 +22,6 @@ class StageF < BaseStage
|
|
24
22
|
|
25
23
|
private
|
26
24
|
|
27
|
-
# rubocop:disable Metrics/AbcSize
|
28
|
-
# rubocop:disable Metrics/MethodLength
|
29
25
|
def run_only_this_concept(table, list1)
|
30
26
|
questions = []
|
31
27
|
lang = concept.lang
|
@@ -69,12 +65,7 @@ class StageF < BaseStage
|
|
69
65
|
end
|
70
66
|
questions
|
71
67
|
end
|
72
|
-
# rubocop:enable Metrics/AbcSize
|
73
|
-
# rubocop:enable Metrics/MethodLength
|
74
68
|
|
75
|
-
# rubocop:disable Lint/BooleanSymbol
|
76
|
-
# rubocop:disable Metrics/MethodLength
|
77
|
-
# rubocop:disable Metrics/AbcSize
|
78
69
|
def make_questions_with(values, table)
|
79
70
|
questions = []
|
80
71
|
lang = concept.lang
|
@@ -124,17 +115,11 @@ class StageF < BaseStage
|
|
124
115
|
q.good = lang.text_for(:misspelling)
|
125
116
|
q.bads << lang.text_for(:true)
|
126
117
|
q.bads << lang.text_for(:false)
|
127
|
-
q.feedback = "Text #{save}
|
118
|
+
q.feedback = "Text #{save} misspelled!"
|
128
119
|
values[0] = save
|
129
120
|
questions << q
|
130
121
|
end
|
131
|
-
# rubocop:enable Lint/BooleanSymbol
|
132
|
-
# rubocop:enable Metrics/MethodLength
|
133
|
-
# rubocop:enable Metrics/AbcSize
|
134
122
|
|
135
|
-
# rubocop:disable Lint/BooleanSymbol
|
136
|
-
# rubocop:disable Metrics/MethodLength
|
137
|
-
# rubocop:disable Metrics/AbcSize
|
138
123
|
def run_with_other_concepts(table, list1, list2)
|
139
124
|
questions = []
|
140
125
|
|
@@ -177,8 +162,4 @@ class StageF < BaseStage
|
|
177
162
|
|
178
163
|
questions
|
179
164
|
end
|
180
|
-
# rubocop:enable Lint/BooleanSymbol
|
181
|
-
# rubocop:enable Metrics/MethodLength
|
182
|
-
# rubocop:enable Metrics/AbcSize
|
183
165
|
end
|
184
|
-
# rubocop:enable Metrics/ClassLength
|
data/lib/asker/application.rb
CHANGED
@@ -0,0 +1,358 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rainbow'
|
4
|
+
|
5
|
+
class InputData
|
6
|
+
attr_reader :inputs, :outputs
|
7
|
+
|
8
|
+
def initialize(filepath)
|
9
|
+
@inputs = File.read(filepath).split("\n")
|
10
|
+
@outputs = []
|
11
|
+
@inputs.each_with_index do |line, index|
|
12
|
+
output = { id: index,
|
13
|
+
level: 0,
|
14
|
+
state: :none,
|
15
|
+
type: :none,
|
16
|
+
source: line,
|
17
|
+
msg: '' }
|
18
|
+
@outputs << output
|
19
|
+
end
|
20
|
+
@ok = false
|
21
|
+
end
|
22
|
+
|
23
|
+
def ok?
|
24
|
+
@ok
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
@outputs.each do |i|
|
29
|
+
puts "#{i[:id]}: #{i[:state]} [#{i[:type]}] #{i[:msg]}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def show_errors
|
34
|
+
errors = 0
|
35
|
+
# puts "Line : Error description"
|
36
|
+
@outputs.each do |i|
|
37
|
+
next if i[:state] == :ok
|
38
|
+
|
39
|
+
errors += 1
|
40
|
+
if errors < 11
|
41
|
+
data = { id: i[:id], msg: i[:msg], source: i[:source][0, 40] }
|
42
|
+
order = i[:id] + 1
|
43
|
+
data = { order: order, msg: i[:msg], source: i[:source][0, 40] }
|
44
|
+
puts format(' %<order>03d : %<msg>s. => %<source>s', data)
|
45
|
+
end
|
46
|
+
puts '...' if errors == 11
|
47
|
+
end
|
48
|
+
|
49
|
+
if errors.positive?
|
50
|
+
puts Rainbow("[ERROR] #{errors} errors " \
|
51
|
+
"from #{@inputs.size} lines!").red.bright
|
52
|
+
end
|
53
|
+
puts Rainbow('Syntax OK!').green if errors.zero?
|
54
|
+
end
|
55
|
+
|
56
|
+
def check
|
57
|
+
@ok = true
|
58
|
+
@inputs.each_with_index do |line, index|
|
59
|
+
check_empty_lines(line, index)
|
60
|
+
check_map(line, index)
|
61
|
+
check_concept(line, index)
|
62
|
+
check_names(line, index)
|
63
|
+
check_tags(line, index)
|
64
|
+
check_def(line, index)
|
65
|
+
check_table(line, index)
|
66
|
+
check_row(line, index)
|
67
|
+
check_col(line, index)
|
68
|
+
check_template(line, index)
|
69
|
+
check_code(line, index)
|
70
|
+
check_type(line, index)
|
71
|
+
check_path(line, index)
|
72
|
+
check_features(line, index)
|
73
|
+
check_unknown(line, index)
|
74
|
+
@ok = false unless @outputs[index][:state] == :ok
|
75
|
+
@ok = false if @outputs[index][:type] == :unkown
|
76
|
+
end
|
77
|
+
@ok
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def check_empty_lines(line, index)
|
83
|
+
return unless line.strip.size.zero? || line.start_with?('#')
|
84
|
+
|
85
|
+
@outputs[index][:type] = :empty
|
86
|
+
@outputs[index][:level] = -1
|
87
|
+
@outputs[index][:state] = :ok
|
88
|
+
end
|
89
|
+
|
90
|
+
def check_map(line, index)
|
91
|
+
if index.zero?
|
92
|
+
@outputs[index][:type] = :map
|
93
|
+
if line.start_with?('%map{')
|
94
|
+
@outputs[index][:state] = :ok
|
95
|
+
else
|
96
|
+
@outputs[index][:state] = :err
|
97
|
+
@outputs[index][:msg] = 'Start with %map{'
|
98
|
+
end
|
99
|
+
elsif index.positive? && line.include?('%map{')
|
100
|
+
@outputs[index][:state] = :err
|
101
|
+
@outputs[index][:type] = :map
|
102
|
+
@outputs[index][:msg] = 'Write %map on line 0'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def check_concept(line, index)
|
107
|
+
return unless @outputs[index][:state] == :none
|
108
|
+
return unless line.include? '%concept'
|
109
|
+
|
110
|
+
@outputs[index][:type] = :concept
|
111
|
+
@outputs[index][:level] = 1
|
112
|
+
@outputs[index][:state] = :ok
|
113
|
+
if find_parent(index) != :map
|
114
|
+
@outputs[index][:state] = :err
|
115
|
+
@outputs[index][:msg] = 'Parent(map) not found!'
|
116
|
+
elsif line != ' %concept'
|
117
|
+
@outputs[index][:state] = :err
|
118
|
+
@outputs[index][:msg] = 'Write 2 spaces before %concept'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def check_names(line, index)
|
123
|
+
return unless @outputs[index][:state] == :none
|
124
|
+
return unless line.include? '%names'
|
125
|
+
|
126
|
+
@outputs[index][:type] = :names
|
127
|
+
@outputs[index][:level] = 2
|
128
|
+
@outputs[index][:state] = :ok
|
129
|
+
if find_parent(index) != :concept
|
130
|
+
@outputs[index][:state] = :err
|
131
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
132
|
+
elsif !line.start_with? ' %names'
|
133
|
+
@outputs[index][:state] = :err
|
134
|
+
@outputs[index][:msg] = 'Write 4 spaces before %names'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def check_tags(line, index)
|
139
|
+
return unless @outputs[index][:state] == :none
|
140
|
+
return unless line.include? '%tags'
|
141
|
+
|
142
|
+
@outputs[index][:type] = :tags
|
143
|
+
@outputs[index][:level] = 2
|
144
|
+
@outputs[index][:state] = :ok
|
145
|
+
if find_parent(index) != :concept
|
146
|
+
@outputs[index][:state] = :err
|
147
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
148
|
+
elsif !line.start_with? ' %tags'
|
149
|
+
@outputs[index][:state] = :err
|
150
|
+
@outputs[index][:msg] = 'Write 4 spaces before %tags'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def check_def(line, index)
|
155
|
+
return unless @outputs[index][:state] == :none
|
156
|
+
return unless line.include? '%def'
|
157
|
+
|
158
|
+
@outputs[index][:type] = :def
|
159
|
+
@outputs[index][:level] = 2
|
160
|
+
@outputs[index][:state] = :ok
|
161
|
+
if find_parent(index) != :concept
|
162
|
+
@outputs[index][:state] = :err
|
163
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
164
|
+
elsif !line.start_with? ' %def'
|
165
|
+
@outputs[index][:state] = :err
|
166
|
+
@outputs[index][:msg] = 'Write 4 spaces before %def'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def check_table(line, index)
|
171
|
+
return unless @outputs[index][:state] == :none
|
172
|
+
return unless line.include? '%table'
|
173
|
+
|
174
|
+
@outputs[index][:type] = :table
|
175
|
+
@outputs[index][:level] = 2
|
176
|
+
@outputs[index][:state] = :ok
|
177
|
+
if find_parent(index) != :concept
|
178
|
+
@outputs[index][:state] = :err
|
179
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
180
|
+
elsif !line.start_with? ' %table'
|
181
|
+
@outputs[index][:state] = :err
|
182
|
+
@outputs[index][:msg] = 'Write 4 spaces before %table'
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def check_row(line, index)
|
187
|
+
return unless @outputs[index][:state] == :none
|
188
|
+
return unless line.include? '%row'
|
189
|
+
|
190
|
+
@outputs[index][:type] = :row
|
191
|
+
@outputs[index][:state] = :ok
|
192
|
+
|
193
|
+
case count_spaces(line)
|
194
|
+
when 6
|
195
|
+
@outputs[index][:level] = 3
|
196
|
+
parent = find_parent(index)
|
197
|
+
unless %i[table features].include? parent
|
198
|
+
@outputs[index][:state] = :err
|
199
|
+
@outputs[index][:msg] = 'Parent(table/features) not found!'
|
200
|
+
end
|
201
|
+
when 8
|
202
|
+
@outputs[index][:level] = 4
|
203
|
+
if find_parent(index) != :template
|
204
|
+
@outputs[index][:state] = :err
|
205
|
+
@outputs[index][:msg] = 'Parent(template) not found!'
|
206
|
+
end
|
207
|
+
else
|
208
|
+
@outputs[index][:state] = :err
|
209
|
+
@outputs[index][:msg] = 'Write 6 or 8 spaces before %row'
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def check_col(line, index)
|
214
|
+
return unless @outputs[index][:state] == :none
|
215
|
+
return unless line.include? '%col'
|
216
|
+
|
217
|
+
@outputs[index][:type] = :col
|
218
|
+
@outputs[index][:state] = :ok
|
219
|
+
case count_spaces(line)
|
220
|
+
when 8
|
221
|
+
@outputs[index][:level] = 4
|
222
|
+
if find_parent(index) != :row
|
223
|
+
@outputs[index][:state] = :err
|
224
|
+
@outputs[index][:msg] = 'Parent(row) not found!'
|
225
|
+
end
|
226
|
+
when 10
|
227
|
+
@outputs[index][:level] = 5
|
228
|
+
if find_parent(index) != :row
|
229
|
+
@outputs[index][:state] = :err
|
230
|
+
@outputs[index][:msg] = 'Parent(row) not found!'
|
231
|
+
end
|
232
|
+
else
|
233
|
+
@outputs[index][:state] = :err
|
234
|
+
@outputs[index][:msg] = 'Write 8 or 10 spaces before %col'
|
235
|
+
end
|
236
|
+
check_text(line, index)
|
237
|
+
end
|
238
|
+
|
239
|
+
def check_text(line, index)
|
240
|
+
return unless @outputs[index][:state] == :ok
|
241
|
+
|
242
|
+
ok = ''
|
243
|
+
%w[< >].each do |char|
|
244
|
+
ok = char if line.include? char
|
245
|
+
end
|
246
|
+
return if ok == ''
|
247
|
+
|
248
|
+
@outputs[index][:state] = :err
|
249
|
+
@outputs[index][:msg] = "Char #{ok} not allow!"
|
250
|
+
end
|
251
|
+
|
252
|
+
def check_template(line, index)
|
253
|
+
return unless @outputs[index][:state] == :none
|
254
|
+
return unless line.include? '%template'
|
255
|
+
|
256
|
+
@outputs[index][:type] = :template
|
257
|
+
@outputs[index][:level] = 3
|
258
|
+
@outputs[index][:state] = :ok
|
259
|
+
if find_parent(index) != :table
|
260
|
+
@outputs[index][:state] = :err
|
261
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
262
|
+
elsif !line.start_with? ' %template'
|
263
|
+
@outputs[index][:state] = :err
|
264
|
+
@outputs[index][:msg] = 'Write 6 spaces before %template'
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def check_code(line, index)
|
269
|
+
return unless @outputs[index][:state] == :none
|
270
|
+
return unless line.include? '%code'
|
271
|
+
|
272
|
+
@outputs[index][:type] = :code
|
273
|
+
@outputs[index][:level] = 1
|
274
|
+
@outputs[index][:state] = :ok
|
275
|
+
if find_parent(index) != :map
|
276
|
+
@outputs[index][:state] = :err
|
277
|
+
@outputs[index][:msg] = 'Parent(map) not found!'
|
278
|
+
elsif line != ' %code'
|
279
|
+
@outputs[index][:state] = :err
|
280
|
+
@outputs[index][:msg] = 'Write 2 spaces before %code'
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
def check_type(line, index)
|
285
|
+
return unless @outputs[index][:state] == :none
|
286
|
+
return unless line.include? '%type'
|
287
|
+
|
288
|
+
@outputs[index][:type] = :type
|
289
|
+
@outputs[index][:level] = 2
|
290
|
+
@outputs[index][:state] = :ok
|
291
|
+
if find_parent(index) != :code
|
292
|
+
@outputs[index][:state] = :err
|
293
|
+
@outputs[index][:msg] = 'Parent(code) not found!'
|
294
|
+
elsif !line.start_with? ' %type'
|
295
|
+
@outputs[index][:state] = :err
|
296
|
+
@outputs[index][:msg] = 'Write 4 spaces before %type'
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
def check_path(line, index)
|
301
|
+
return unless @outputs[index][:state] == :none
|
302
|
+
return unless line.include? '%path'
|
303
|
+
|
304
|
+
@outputs[index][:type] = :path
|
305
|
+
@outputs[index][:level] = 2
|
306
|
+
@outputs[index][:state] = :ok
|
307
|
+
if find_parent(index) != :code
|
308
|
+
@outputs[index][:state] = :err
|
309
|
+
@outputs[index][:msg] = 'Parent(code) not found!'
|
310
|
+
elsif !line.start_with? ' %path'
|
311
|
+
@outputs[index][:state] = :err
|
312
|
+
@outputs[index][:msg] = 'Write 4 spaces before %type'
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
def check_features(line, index)
|
317
|
+
return unless @outputs[index][:state] == :none
|
318
|
+
return unless line.include? '%features'
|
319
|
+
|
320
|
+
@outputs[index][:type] = :features
|
321
|
+
@outputs[index][:level] = 2
|
322
|
+
@outputs[index][:state] = :ok
|
323
|
+
if find_parent(index) != :code
|
324
|
+
@outputs[index][:state] = :err
|
325
|
+
@outputs[index][:msg] = 'Parent(code) not found!'
|
326
|
+
elsif !line.start_with? ' %features'
|
327
|
+
@outputs[index][:state] = :err
|
328
|
+
@outputs[index][:msg] = 'Write 4 spaces before %features'
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
def check_unknown(line, index)
|
333
|
+
return unless @outputs[index][:state] == :none
|
334
|
+
|
335
|
+
@outputs[index][:type] = :unknown
|
336
|
+
@outputs[index][:level] = count_spaces(line) / 2
|
337
|
+
@outputs[index][:state] = :err
|
338
|
+
@outputs[index][:msg] = "Unknown tag with parent(#{find_parent(index)})!"
|
339
|
+
end
|
340
|
+
|
341
|
+
def find_parent(index)
|
342
|
+
current_level = @outputs[index][:level]
|
343
|
+
return :noparent if current_level.zero?
|
344
|
+
|
345
|
+
i = index - 1
|
346
|
+
while i >= 0
|
347
|
+
return @outputs[i][:type] if @outputs[i][:level] == current_level - 1
|
348
|
+
|
349
|
+
i -= 1
|
350
|
+
end
|
351
|
+
:noparent
|
352
|
+
end
|
353
|
+
|
354
|
+
def count_spaces(line)
|
355
|
+
a = line.split('%')
|
356
|
+
a[0].count(' ')
|
357
|
+
end
|
358
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rainbow'
|
4
|
+
require_relative 'check_input/input_data'
|
5
|
+
|
6
|
+
class CheckInput
|
7
|
+
def initialize(verbose = true)
|
8
|
+
@verbose = verbose
|
9
|
+
end
|
10
|
+
|
11
|
+
def file(filepath)
|
12
|
+
@filepath = filepath
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def verbose(verbose)
|
17
|
+
@verbose = verbose
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def check
|
22
|
+
# Check HAML file syntax
|
23
|
+
exist = check_file_exist
|
24
|
+
return false unless exist
|
25
|
+
check_file_content
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def check_file_exist
|
31
|
+
if @filepath.nil?
|
32
|
+
raise Rainbow("Can't check nil filename")
|
33
|
+
end
|
34
|
+
unless File.exist? @filepath
|
35
|
+
puts Rainbow('File not found!').red.bright if @verbose
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
unless File.extname(@filepath) == '.haml'
|
39
|
+
puts Rainbow('Only check HAML files!').yellow.bright if @verbose
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_file_content
|
46
|
+
data = InputData.new(@filepath)
|
47
|
+
data.check
|
48
|
+
data.show_errors if @verbose
|
49
|
+
data.ok?
|
50
|
+
end
|
51
|
+
end
|
@@ -12,8 +12,6 @@ module ContentLoader
|
|
12
12
|
# Load XML content into Asker data objects
|
13
13
|
# @param filepath (String) File path
|
14
14
|
# @param content (String) XML plane text content
|
15
|
-
# rubocop:disable Metrics/MethodLength
|
16
|
-
# rubocop:disable Metrics/AbcSize
|
17
15
|
def self.load(filepath, content)
|
18
16
|
concepts = []
|
19
17
|
codes = []
|
@@ -94,7 +92,9 @@ module ContentLoader
|
|
94
92
|
# @param filepath (String)
|
95
93
|
# @param content (String)
|
96
94
|
private_class_method def self.raise_error_with(filepath, content)
|
97
|
-
|
95
|
+
msg = "[ERROR] ContentLoader: Format error in #{filepath}\n"
|
96
|
+
msg += " Take a look at ouput/error.xml"
|
97
|
+
puts Rainbow(msg).red.bright
|
98
98
|
f = File.open('output/error.xml', 'w')
|
99
99
|
f.write(content)
|
100
100
|
f.close
|
data/lib/asker.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'rainbow'
|
4
4
|
|
5
5
|
require_relative 'asker/skeleton'
|
6
|
-
require_relative 'asker/
|
6
|
+
require_relative 'asker/check_input'
|
7
7
|
|
8
8
|
require_relative 'asker/displayer/concept_displayer'
|
9
9
|
require_relative 'asker/displayer/stats_displayer'
|
@@ -12,7 +12,6 @@ require_relative 'asker/logger'
|
|
12
12
|
|
13
13
|
require_relative 'asker/loader/project_loader'
|
14
14
|
require_relative 'asker/loader/input_loader'
|
15
|
-
|
16
15
|
class Asker
|
17
16
|
def self.init
|
18
17
|
Skeleton.create_configuration
|
@@ -23,7 +22,7 @@ class Asker
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def self.check(filepath)
|
26
|
-
|
25
|
+
CheckInput.new.file(filepath).check
|
27
26
|
end
|
28
27
|
|
29
28
|
def self.start(filepath)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asker-tool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Vargas Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rexml
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: terminal-table
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,20 @@ dependencies:
|
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '5.11'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.9'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.9'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: rubocop
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,6 +170,8 @@ files:
|
|
142
170
|
- lib/asker/ai/stages/stage_s.rb
|
143
171
|
- lib/asker/ai/stages/stage_t.rb
|
144
172
|
- lib/asker/application.rb
|
173
|
+
- lib/asker/check_input.rb
|
174
|
+
- lib/asker/check_input/input_data.rb
|
145
175
|
- lib/asker/cli.rb
|
146
176
|
- lib/asker/data/code.rb
|
147
177
|
- lib/asker/data/column.rb
|
@@ -206,7 +236,6 @@ files:
|
|
206
236
|
- lib/asker/formatter/question_moodle_formatter.rb
|
207
237
|
- lib/asker/formatter/question_moodlexml_formatter.rb
|
208
238
|
- lib/asker/formatter/rb2haml_formatter.rb
|
209
|
-
- lib/asker/input_checker.rb
|
210
239
|
- lib/asker/lang/lang.rb
|
211
240
|
- lib/asker/lang/lang_factory.rb
|
212
241
|
- lib/asker/lang/text_actions.rb
|
data/lib/asker/input_checker.rb
DELETED
@@ -1,450 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rainbow'
|
4
|
-
|
5
|
-
##
|
6
|
-
# Check HAML file syntax
|
7
|
-
module InputChecker
|
8
|
-
|
9
|
-
def self.check(filepath, verbose = true)
|
10
|
-
exist = check_file_exist(filepath, verbose)
|
11
|
-
return false unless exist
|
12
|
-
check_file_content(filepath, verbose)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.check_file_exist(filepath, verbose = true)
|
16
|
-
unless File.exist? filepath
|
17
|
-
puts Rainbow('File not found!').red.bright if verbose
|
18
|
-
return false
|
19
|
-
end
|
20
|
-
unless File.extname(filepath) == '.haml'
|
21
|
-
puts Rainbow('Only check HAML files!').yellow.bright if verbose
|
22
|
-
return false
|
23
|
-
end
|
24
|
-
true
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.check_file_content(filepath, verbose = true)
|
28
|
-
data = Data.new(filepath)
|
29
|
-
data.check
|
30
|
-
data.show_errors if verbose
|
31
|
-
data.ok?
|
32
|
-
end
|
33
|
-
|
34
|
-
# rubocop:disable Metrics/ClassLength
|
35
|
-
class Data
|
36
|
-
attr_reader :inputs, :outputs
|
37
|
-
|
38
|
-
# rubocop:disable Metrics/MethodLength
|
39
|
-
def initialize(filepath)
|
40
|
-
@inputs = File.read(filepath).split("\n")
|
41
|
-
@outputs = []
|
42
|
-
@inputs.each_with_index do |line, index|
|
43
|
-
output = { id: index,
|
44
|
-
level: 0,
|
45
|
-
state: :none,
|
46
|
-
type: :none,
|
47
|
-
source: line,
|
48
|
-
msg: '' }
|
49
|
-
@outputs << output
|
50
|
-
end
|
51
|
-
@ok = false
|
52
|
-
end
|
53
|
-
# rubocop:enable Metrics/MethodLength
|
54
|
-
|
55
|
-
def ok?
|
56
|
-
@ok
|
57
|
-
end
|
58
|
-
|
59
|
-
def show
|
60
|
-
@outputs.each do |i|
|
61
|
-
puts "#{i[:id]}: #{i[:state]} [#{i[:type]}] #{i[:msg]}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def show_errors
|
66
|
-
errors = 0
|
67
|
-
# puts "Line : Error description"
|
68
|
-
@outputs.each do |i|
|
69
|
-
next if i[:state] == :ok
|
70
|
-
|
71
|
-
errors += 1
|
72
|
-
if errors < 11
|
73
|
-
data = { id: i[:id], msg: i[:msg], source: i[:source][0, 40] }
|
74
|
-
order = i[:id] + 1
|
75
|
-
data = { order: order, msg: i[:msg], source: i[:source][0, 40] }
|
76
|
-
puts format(' %<order>03d : %<msg>s. => %<source>s', data)
|
77
|
-
end
|
78
|
-
puts '...' if errors == 11
|
79
|
-
end
|
80
|
-
|
81
|
-
if errors.positive?
|
82
|
-
puts Rainbow("[ERROR] #{errors} errors " \
|
83
|
-
"from #{@inputs.size} lines!").red.bright
|
84
|
-
end
|
85
|
-
puts Rainbow('Syntax OK!').green if errors.zero?
|
86
|
-
end
|
87
|
-
# rubocop:enable Metrics/AbcSize
|
88
|
-
# rubocop:enable Metrics/MethodLength
|
89
|
-
|
90
|
-
# rubocop:disable Metrics/MethodLength
|
91
|
-
# rubocop:disable Metrics/AbcSize
|
92
|
-
def check
|
93
|
-
@ok = true
|
94
|
-
@inputs.each_with_index do |line, index|
|
95
|
-
check_empty_lines(line, index)
|
96
|
-
check_map(line, index)
|
97
|
-
check_concept(line, index)
|
98
|
-
check_names(line, index)
|
99
|
-
check_tags(line, index)
|
100
|
-
check_def(line, index)
|
101
|
-
check_table(line, index)
|
102
|
-
check_row(line, index)
|
103
|
-
check_col(line, index)
|
104
|
-
check_template(line, index)
|
105
|
-
check_code(line, index)
|
106
|
-
check_type(line, index)
|
107
|
-
check_path(line, index)
|
108
|
-
check_features(line, index)
|
109
|
-
check_unknown(line, index)
|
110
|
-
@ok = false unless @outputs[index][:state] == :ok
|
111
|
-
@ok = false if @outputs[index][:type] == :unkown
|
112
|
-
end
|
113
|
-
@ok
|
114
|
-
end
|
115
|
-
# rubocop:enable Metrics/MethodLength
|
116
|
-
# rubocop:enable Metrics/AbcSize
|
117
|
-
|
118
|
-
private
|
119
|
-
|
120
|
-
def check_empty_lines(line, index)
|
121
|
-
return unless line.strip.size.zero? || line.start_with?('#')
|
122
|
-
|
123
|
-
@outputs[index][:type] = :empty
|
124
|
-
@outputs[index][:level] = -1
|
125
|
-
@outputs[index][:state] = :ok
|
126
|
-
end
|
127
|
-
|
128
|
-
# rubocop:disable Metrics/MethodLength
|
129
|
-
# rubocop:disable Metrics/AbcSize
|
130
|
-
def check_map(line, index)
|
131
|
-
if index.zero?
|
132
|
-
@outputs[index][:type] = :map
|
133
|
-
if line.start_with?('%map{')
|
134
|
-
@outputs[index][:state] = :ok
|
135
|
-
else
|
136
|
-
@outputs[index][:state] = :err
|
137
|
-
@outputs[index][:msg] = 'Start with %map{'
|
138
|
-
end
|
139
|
-
elsif index.positive? && line.include?('%map{')
|
140
|
-
@outputs[index][:state] = :err
|
141
|
-
@outputs[index][:type] = :map
|
142
|
-
@outputs[index][:msg] = 'Write %map on line 0'
|
143
|
-
end
|
144
|
-
end
|
145
|
-
# rubocop:enable Metrics/MethodLength
|
146
|
-
# rubocop:enable Metrics/AbcSize
|
147
|
-
|
148
|
-
# rubocop:disable Metrics/MethodLength
|
149
|
-
# rubocop:disable Metrics/AbcSize
|
150
|
-
def check_concept(line, index)
|
151
|
-
return unless @outputs[index][:state] == :none
|
152
|
-
return unless line.include? '%concept'
|
153
|
-
|
154
|
-
@outputs[index][:type] = :concept
|
155
|
-
@outputs[index][:level] = 1
|
156
|
-
@outputs[index][:state] = :ok
|
157
|
-
if find_parent(index) != :map
|
158
|
-
@outputs[index][:state] = :err
|
159
|
-
@outputs[index][:msg] = 'Parent(map) not found!'
|
160
|
-
elsif line != ' %concept'
|
161
|
-
@outputs[index][:state] = :err
|
162
|
-
@outputs[index][:msg] = 'Write 2 spaces before %concept'
|
163
|
-
end
|
164
|
-
end
|
165
|
-
# rubocop:enable Metrics/MethodLength
|
166
|
-
# rubocop:enable Metrics/AbcSize
|
167
|
-
|
168
|
-
# rubocop:disable Metrics/AbcSize
|
169
|
-
# rubocop:disable Metrics/MethodLength
|
170
|
-
def check_names(line, index)
|
171
|
-
return unless @outputs[index][:state] == :none
|
172
|
-
return unless line.include? '%names'
|
173
|
-
|
174
|
-
@outputs[index][:type] = :names
|
175
|
-
@outputs[index][:level] = 2
|
176
|
-
@outputs[index][:state] = :ok
|
177
|
-
if find_parent(index) != :concept
|
178
|
-
@outputs[index][:state] = :err
|
179
|
-
@outputs[index][:msg] = 'Parent(concept) not found!'
|
180
|
-
elsif !line.start_with? ' %names'
|
181
|
-
@outputs[index][:state] = :err
|
182
|
-
@outputs[index][:msg] = 'Write 4 spaces before %names'
|
183
|
-
end
|
184
|
-
end
|
185
|
-
# rubocop:enable Metrics/AbcSize
|
186
|
-
# rubocop:enable Metrics/MethodLength
|
187
|
-
|
188
|
-
# rubocop:disable Metrics/AbcSize
|
189
|
-
# rubocop:disable Metrics/MethodLength
|
190
|
-
def check_tags(line, index)
|
191
|
-
return unless @outputs[index][:state] == :none
|
192
|
-
return unless line.include? '%tags'
|
193
|
-
|
194
|
-
@outputs[index][:type] = :tags
|
195
|
-
@outputs[index][:level] = 2
|
196
|
-
@outputs[index][:state] = :ok
|
197
|
-
if find_parent(index) != :concept
|
198
|
-
@outputs[index][:state] = :err
|
199
|
-
@outputs[index][:msg] = 'Parent(concept) not found!'
|
200
|
-
elsif !line.start_with? ' %tags'
|
201
|
-
@outputs[index][:state] = :err
|
202
|
-
@outputs[index][:msg] = 'Write 4 spaces before %tags'
|
203
|
-
end
|
204
|
-
end
|
205
|
-
# rubocop:enable Metrics/AbcSize
|
206
|
-
# rubocop:enable Metrics/MethodLength
|
207
|
-
|
208
|
-
# rubocop:disable Metrics/AbcSize
|
209
|
-
# rubocop:disable Metrics/MethodLength
|
210
|
-
def check_def(line, index)
|
211
|
-
return unless @outputs[index][:state] == :none
|
212
|
-
return unless line.include? '%def'
|
213
|
-
|
214
|
-
@outputs[index][:type] = :def
|
215
|
-
@outputs[index][:level] = 2
|
216
|
-
@outputs[index][:state] = :ok
|
217
|
-
if find_parent(index) != :concept
|
218
|
-
@outputs[index][:state] = :err
|
219
|
-
@outputs[index][:msg] = 'Parent(concept) not found!'
|
220
|
-
elsif !line.start_with? ' %def'
|
221
|
-
@outputs[index][:state] = :err
|
222
|
-
@outputs[index][:msg] = 'Write 4 spaces before %def'
|
223
|
-
end
|
224
|
-
end
|
225
|
-
# rubocop:enable Metrics/AbcSize
|
226
|
-
# rubocop:enable Metrics/MethodLength
|
227
|
-
|
228
|
-
# rubocop:disable Metrics/AbcSize
|
229
|
-
# rubocop:disable Metrics/MethodLength
|
230
|
-
def check_table(line, index)
|
231
|
-
return unless @outputs[index][:state] == :none
|
232
|
-
return unless line.include? '%table'
|
233
|
-
|
234
|
-
@outputs[index][:type] = :table
|
235
|
-
@outputs[index][:level] = 2
|
236
|
-
@outputs[index][:state] = :ok
|
237
|
-
if find_parent(index) != :concept
|
238
|
-
@outputs[index][:state] = :err
|
239
|
-
@outputs[index][:msg] = 'Parent(concept) not found!'
|
240
|
-
elsif !line.start_with? ' %table'
|
241
|
-
@outputs[index][:state] = :err
|
242
|
-
@outputs[index][:msg] = 'Write 4 spaces before %table'
|
243
|
-
end
|
244
|
-
end
|
245
|
-
# rubocop:enable Metrics/AbcSize
|
246
|
-
# rubocop:enable Metrics/MethodLength
|
247
|
-
|
248
|
-
# rubocop:disable Metrics/AbcSize
|
249
|
-
# rubocop:disable Metrics/MethodLength
|
250
|
-
def check_row(line, index)
|
251
|
-
return unless @outputs[index][:state] == :none
|
252
|
-
return unless line.include? '%row'
|
253
|
-
|
254
|
-
@outputs[index][:type] = :row
|
255
|
-
@outputs[index][:state] = :ok
|
256
|
-
|
257
|
-
case count_spaces(line)
|
258
|
-
when 6
|
259
|
-
@outputs[index][:level] = 3
|
260
|
-
parent = find_parent(index)
|
261
|
-
unless %i[table features].include? parent
|
262
|
-
@outputs[index][:state] = :err
|
263
|
-
@outputs[index][:msg] = 'Parent(table/features) not found!'
|
264
|
-
end
|
265
|
-
when 8
|
266
|
-
@outputs[index][:level] = 4
|
267
|
-
if find_parent(index) != :template
|
268
|
-
@outputs[index][:state] = :err
|
269
|
-
@outputs[index][:msg] = 'Parent(template) not found!'
|
270
|
-
end
|
271
|
-
else
|
272
|
-
@outputs[index][:state] = :err
|
273
|
-
@outputs[index][:msg] = 'Write 6 or 8 spaces before %row'
|
274
|
-
end
|
275
|
-
end
|
276
|
-
# rubocop:enable Metrics/AbcSize
|
277
|
-
# rubocop:enable Metrics/MethodLength
|
278
|
-
|
279
|
-
# rubocop:disable Metrics/AbcSize
|
280
|
-
# rubocop:disable Metrics/MethodLength
|
281
|
-
def check_col(line, index)
|
282
|
-
return unless @outputs[index][:state] == :none
|
283
|
-
return unless line.include? '%col'
|
284
|
-
|
285
|
-
@outputs[index][:type] = :col
|
286
|
-
@outputs[index][:state] = :ok
|
287
|
-
case count_spaces(line)
|
288
|
-
when 8
|
289
|
-
@outputs[index][:level] = 4
|
290
|
-
if find_parent(index) != :row
|
291
|
-
@outputs[index][:state] = :err
|
292
|
-
@outputs[index][:msg] = 'Parent(row) not found!'
|
293
|
-
end
|
294
|
-
when 10
|
295
|
-
@outputs[index][:level] = 5
|
296
|
-
if find_parent(index) != :row
|
297
|
-
@outputs[index][:state] = :err
|
298
|
-
@outputs[index][:msg] = 'Parent(row) not found!'
|
299
|
-
end
|
300
|
-
else
|
301
|
-
@outputs[index][:state] = :err
|
302
|
-
@outputs[index][:msg] = 'Write 8 or 10 spaces before %col'
|
303
|
-
end
|
304
|
-
check_text(line, index)
|
305
|
-
end
|
306
|
-
# rubocop:enable Metrics/AbcSize
|
307
|
-
# rubocop:enable Metrics/MethodLength
|
308
|
-
|
309
|
-
def check_text(line, index)
|
310
|
-
return unless @outputs[index][:state] == :ok
|
311
|
-
|
312
|
-
ok = ''
|
313
|
-
%w[< >].each do |char|
|
314
|
-
ok = char if line.include? char
|
315
|
-
end
|
316
|
-
return if ok == ''
|
317
|
-
|
318
|
-
@outputs[index][:state] = :err
|
319
|
-
@outputs[index][:msg] = "Char #{ok} not allow!"
|
320
|
-
end
|
321
|
-
|
322
|
-
# rubocop:disable Metrics/MethodLength
|
323
|
-
# rubocop:disable Metrics/AbcSize
|
324
|
-
def check_template(line, index)
|
325
|
-
return unless @outputs[index][:state] == :none
|
326
|
-
return unless line.include? '%template'
|
327
|
-
|
328
|
-
@outputs[index][:type] = :template
|
329
|
-
@outputs[index][:level] = 3
|
330
|
-
@outputs[index][:state] = :ok
|
331
|
-
if find_parent(index) != :table
|
332
|
-
@outputs[index][:state] = :err
|
333
|
-
@outputs[index][:msg] = 'Parent(concept) not found!'
|
334
|
-
elsif !line.start_with? ' %template'
|
335
|
-
@outputs[index][:state] = :err
|
336
|
-
@outputs[index][:msg] = 'Write 6 spaces before %template'
|
337
|
-
end
|
338
|
-
end
|
339
|
-
# rubocop:enable Metrics/AbcSize
|
340
|
-
# rubocop:enable Metrics/MethodLength
|
341
|
-
|
342
|
-
# rubocop:disable Metrics/MethodLength
|
343
|
-
# rubocop:disable Metrics/AbcSize
|
344
|
-
def check_code(line, index)
|
345
|
-
return unless @outputs[index][:state] == :none
|
346
|
-
return unless line.include? '%code'
|
347
|
-
|
348
|
-
@outputs[index][:type] = :code
|
349
|
-
@outputs[index][:level] = 1
|
350
|
-
@outputs[index][:state] = :ok
|
351
|
-
if find_parent(index) != :map
|
352
|
-
@outputs[index][:state] = :err
|
353
|
-
@outputs[index][:msg] = 'Parent(map) not found!'
|
354
|
-
elsif line != ' %code'
|
355
|
-
@outputs[index][:state] = :err
|
356
|
-
@outputs[index][:msg] = 'Write 2 spaces before %code'
|
357
|
-
end
|
358
|
-
end
|
359
|
-
# rubocop:enable Metrics/MethodLength
|
360
|
-
# rubocop:enable Metrics/AbcSize
|
361
|
-
|
362
|
-
# rubocop:disable Metrics/MethodLength
|
363
|
-
# rubocop:disable Metrics/AbcSize
|
364
|
-
def check_type(line, index)
|
365
|
-
return unless @outputs[index][:state] == :none
|
366
|
-
return unless line.include? '%type'
|
367
|
-
|
368
|
-
@outputs[index][:type] = :type
|
369
|
-
@outputs[index][:level] = 2
|
370
|
-
@outputs[index][:state] = :ok
|
371
|
-
if find_parent(index) != :code
|
372
|
-
@outputs[index][:state] = :err
|
373
|
-
@outputs[index][:msg] = 'Parent(code) not found!'
|
374
|
-
elsif !line.start_with? ' %type'
|
375
|
-
@outputs[index][:state] = :err
|
376
|
-
@outputs[index][:msg] = 'Write 4 spaces before %type'
|
377
|
-
end
|
378
|
-
end
|
379
|
-
# rubocop:enable Metrics/AbcSize
|
380
|
-
# rubocop:enable Metrics/MethodLength
|
381
|
-
|
382
|
-
# rubocop:disable Metrics/MethodLength
|
383
|
-
# rubocop:disable Metrics/AbcSize
|
384
|
-
def check_path(line, index)
|
385
|
-
return unless @outputs[index][:state] == :none
|
386
|
-
return unless line.include? '%path'
|
387
|
-
|
388
|
-
@outputs[index][:type] = :path
|
389
|
-
@outputs[index][:level] = 2
|
390
|
-
@outputs[index][:state] = :ok
|
391
|
-
if find_parent(index) != :code
|
392
|
-
@outputs[index][:state] = :err
|
393
|
-
@outputs[index][:msg] = 'Parent(code) not found!'
|
394
|
-
elsif !line.start_with? ' %path'
|
395
|
-
@outputs[index][:state] = :err
|
396
|
-
@outputs[index][:msg] = 'Write 4 spaces before %type'
|
397
|
-
end
|
398
|
-
end
|
399
|
-
# rubocop:enable Metrics/AbcSize
|
400
|
-
# rubocop:enable Metrics/MethodLength
|
401
|
-
|
402
|
-
# rubocop:disable Metrics/MethodLength
|
403
|
-
# rubocop:disable Metrics/AbcSize
|
404
|
-
def check_features(line, index)
|
405
|
-
return unless @outputs[index][:state] == :none
|
406
|
-
return unless line.include? '%features'
|
407
|
-
|
408
|
-
@outputs[index][:type] = :features
|
409
|
-
@outputs[index][:level] = 2
|
410
|
-
@outputs[index][:state] = :ok
|
411
|
-
if find_parent(index) != :code
|
412
|
-
@outputs[index][:state] = :err
|
413
|
-
@outputs[index][:msg] = 'Parent(code) not found!'
|
414
|
-
elsif !line.start_with? ' %features'
|
415
|
-
@outputs[index][:state] = :err
|
416
|
-
@outputs[index][:msg] = 'Write 4 spaces before %features'
|
417
|
-
end
|
418
|
-
end
|
419
|
-
# rubocop:enable Metrics/AbcSize
|
420
|
-
# rubocop:enable Metrics/MethodLength
|
421
|
-
|
422
|
-
def check_unknown(line, index)
|
423
|
-
return unless @outputs[index][:state] == :none
|
424
|
-
|
425
|
-
@outputs[index][:type] = :unknown
|
426
|
-
@outputs[index][:level] = count_spaces(line) / 2
|
427
|
-
@outputs[index][:state] = :err
|
428
|
-
@outputs[index][:msg] = "Unknown tag with parent(#{find_parent(index)})!"
|
429
|
-
end
|
430
|
-
|
431
|
-
def find_parent(index)
|
432
|
-
current_level = @outputs[index][:level]
|
433
|
-
return :noparent if current_level.zero?
|
434
|
-
|
435
|
-
i = index - 1
|
436
|
-
while i >= 0
|
437
|
-
return @outputs[i][:type] if @outputs[i][:level] == current_level - 1
|
438
|
-
|
439
|
-
i -= 1
|
440
|
-
end
|
441
|
-
:noparent
|
442
|
-
end
|
443
|
-
|
444
|
-
def count_spaces(line)
|
445
|
-
a = line.split('%')
|
446
|
-
a[0].count(' ')
|
447
|
-
end
|
448
|
-
end
|
449
|
-
# rubocop:enable Metrics/ClassLength
|
450
|
-
end
|