asker-tool 2.1.7 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE.txt → LICENSE} +0 -0
  3. data/README.md +1 -1
  4. data/bin/asker +1 -1
  5. data/lib/asker/ai/ai.rb +6 -3
  6. data/lib/asker/ai/ai_calculate.rb +20 -6
  7. data/lib/asker/ai/concept_ai.rb +11 -2
  8. data/lib/asker/ai/question.rb +28 -6
  9. data/lib/asker/ai/stages/base_stage.rb +45 -6
  10. data/lib/asker/ai/stages/stage_b.rb +100 -50
  11. data/lib/asker/ai/stages/stage_d.rb +75 -90
  12. data/lib/asker/ai/stages/stage_f.rb +64 -36
  13. data/lib/asker/ai/stages/stage_i.rb +79 -92
  14. data/lib/asker/ai/stages/stage_s.rb +41 -36
  15. data/lib/asker/ai/stages/stage_t.rb +114 -73
  16. data/lib/asker/application.rb +8 -7
  17. data/lib/asker/checker.rb +6 -8
  18. data/lib/asker/cli.rb +27 -9
  19. data/lib/asker/data/code.rb +4 -1
  20. data/lib/asker/data/concept.rb +67 -21
  21. data/lib/asker/data/table.rb +2 -0
  22. data/lib/asker/data/template.rb +3 -1
  23. data/lib/asker/data/world.rb +7 -4
  24. data/lib/asker/displayer/code_displayer.rb +7 -0
  25. data/lib/asker/displayer/concept_ai_displayer.erb +10 -0
  26. data/lib/asker/displayer/concept_ai_displayer.rb +23 -22
  27. data/lib/asker/displayer/concept_displayer.rb +9 -4
  28. data/lib/asker/displayer/stats_displayer.rb +8 -0
  29. data/lib/asker/exporter/concept_ai_gift_exporter.rb +7 -11
  30. data/lib/asker/exporter/concept_ai_moodle_exporter.rb +44 -0
  31. data/lib/asker/exporter/concept_ai_yaml_exporter.rb +6 -3
  32. data/lib/asker/exporter/concept_doc_exporter.rb +14 -1
  33. data/lib/asker/exporter/data_gift_exporter.rb +29 -0
  34. data/lib/asker/exporter/output_file_exporter.rb +9 -6
  35. data/lib/asker/files/{config.ini → asker.ini} +14 -4
  36. data/lib/asker/files/language/du/connectors.yaml +81 -0
  37. data/lib/asker/files/language/du/mistakes.yaml +82 -0
  38. data/lib/asker/files/language/du/templates.yaml +28 -49
  39. data/lib/asker/files/language/en/templates.yaml +19 -19
  40. data/lib/asker/files/language/es/mistakes.yaml +9 -7
  41. data/lib/asker/files/language/es/templates.yaml +19 -19
  42. data/lib/asker/files/language/fr/connectors.yaml +68 -84
  43. data/lib/asker/files/language/fr/templates.yaml +22 -22
  44. data/lib/asker/formatter/concept_string_formatter.rb +7 -4
  45. data/lib/asker/formatter/moodle/matching.erb +38 -0
  46. data/lib/asker/formatter/moodle/multichoice.erb +49 -0
  47. data/lib/asker/formatter/moodle/shortanswer.erb +30 -0
  48. data/lib/asker/formatter/moodle/truefalse.erb +47 -0
  49. data/lib/asker/formatter/question_gift_formatter.rb +21 -19
  50. data/lib/asker/formatter/question_moodle_formatter.rb +27 -0
  51. data/lib/asker/lang/lang_factory.rb +7 -1
  52. data/lib/asker/loader/code_loader.rb +1 -1
  53. data/lib/asker/loader/content_loader.rb +7 -7
  54. data/lib/asker/loader/directory_loader.rb +3 -3
  55. data/lib/asker/loader/embedded_file.rb +42 -0
  56. data/lib/asker/loader/file_loader.rb +1 -1
  57. data/lib/asker/loader/image_url_loader.rb +4 -3
  58. data/lib/asker/loader/input_loader.rb +1 -1
  59. data/lib/asker/loader/project_loader.rb +14 -5
  60. data/lib/asker/logger.rb +29 -4
  61. data/lib/asker/project.rb +14 -79
  62. data/lib/asker/skeleton.rb +3 -2
  63. data/lib/asker.rb +37 -9
  64. metadata +19 -22
@@ -1,52 +1,57 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base_stage'
4
4
  require_relative '../question'
5
5
 
6
+ # process_sequence
6
7
  class StageS < BaseStage
7
-
8
- def run(pTable, pList1, pList2)
9
- #process_sequence
8
+ # process_sequence
9
+ # rubocop:disable Metrics/MethodLength
10
+ # rubocop:disable Metrics/AbcSize
11
+ # rubocop:disable Metrics/CyclomaticComplexity
12
+ # rubocop:disable Metrics/PerceivedComplexity
13
+ def run(table, list1, _list2)
10
14
  questions = []
11
- return questions unless ( pTable.fields.count==1 and pTable.sequence? and pTable.sequence[0]!="")
12
-
13
- #TODO
14
- #items=[]
15
- #pList1.each_with_index { |i,j| items<<[ i[:data][0], j] }
16
- #puts Rainbow(items).blue.bright
17
-
18
- #Question type <d3sequence>: items are part of a sequence
19
- if pList1.count>3
20
- a=0..(pList1.count-4)
21
- a.each_entry do |i|
22
- q=Question.new(:match)
23
- q.name="#{name}-#{num.to_s}-s1sequence-#{pTable.name}"
24
- q.text= random_image_for(name) + lang.text_for(:s1, name, pTable.fields[0].capitalize, pTable.sequence[0] )
25
- q.matching << [ pList1[i+0][:data][0], '' ]
26
- q.matching << [ pList1[i+1][:data][0], '2º' ]
27
- q.matching << [ pList1[i+2][:data][0], '3º' ]
28
- q.matching << [ pList1[i+3][:data][0], '4º' ]
15
+ return questions unless table.fields.count == 1 && table.sequence? && table.sequence[0] != ''
16
+
17
+ lang = concept.lang
18
+ # Question type <d3sequence>: items are part of a sequence
19
+ if list1.count > 3
20
+ a = 0..(list1.count - 4)
21
+ a.each_entry do |i|
22
+ q = Question.new(:match)
23
+ q.name = "#{name}-#{num}-s1sequence-#{table.name}"
24
+ q.text = random_image_for(name) + lang.text_for(:s1, name, table.fields[0].capitalize, table.sequence[0])
25
+ q.matching << [list1[i + 0][:data][0], '1º']
26
+ q.matching << [list1[i + 1][:data][0], '2º']
27
+ q.matching << [list1[i + 2][:data][0], '3º']
28
+ q.matching << [list1[i + 3][:data][0], '4º']
29
+ q.matching << ['', lang.text_for(:error)]
29
30
  questions << q
30
31
  end
31
32
  end
32
33
 
33
- #Question type <d4sequence>: items are part of a reverse sequence
34
- if pList1.count>3 and pTable.sequence.size>1
35
- a=0..(pList1.count-4)
36
- a.each_entry do |i|
37
- q=Question.new
34
+ # Question type <d4sequence>: items are part of a reverse sequence
35
+ if list1.count > 3 && table.sequence.size > 1
36
+ a = 0..(list1.count - 4)
37
+ a.each_entry do |i|
38
+ q = Question.new
38
39
  q.set_match
39
- q.name="#{name}-#{num.to_s}-s2sequence-#{pTable.name}"
40
- q.text= random_image_for(name) + lang.text_for(:s1, name, pTable.fields[0].capitalize, pTable.sequence[1] )
41
- q.matching << [ pList1[i+3][:data][0], '1º' ]
42
- q.matching << [ pList1[i+2][:data][0], '2º' ]
43
- q.matching << [ pList1[i+1][:data][0], '3º' ]
44
- q.matching << [ pList1[i+0][:data][0], '4º' ]
40
+ q.name = "#{name}-#{num}-s2sequence-#{table.name}"
41
+ q.text = random_image_for(name) + lang.text_for(:s1, name, table.fields[0].capitalize, table.sequence[1])
42
+ q.matching << [list1[i + 3][:data][0], '1º']
43
+ q.matching << [list1[i + 2][:data][0], '2º']
44
+ q.matching << [list1[i + 1][:data][0], '3º']
45
+ q.matching << [list1[i + 0][:data][0], '4º']
46
+ q.matching << ['', lang.text_for(:error)]
45
47
  questions << q
46
48
  end
47
- end
49
+ end
48
50
 
49
- return questions
51
+ questions
50
52
  end
51
-
53
+ # rubocop:enable Metrics/MethodLength
54
+ # rubocop:enable Metrics/AbcSize
55
+ # rubocop:enable Metrics/CyclomaticComplexity
56
+ # rubocop:enable Metrics/PerceivedComplexity
52
57
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require 'set'
3
4
  require_relative 'base_stage'
@@ -5,56 +6,71 @@ require_relative '../question'
5
6
 
6
7
  ##
7
8
  # StageT create questions based con Table data
9
+ # range t1-t9
10
+ # rubocop:disable Metrics/ClassLength
8
11
  class StageT < BaseStage
9
- # range t1-t9
10
-
11
- def run(pTable, pRow, pList) # process_tableXfields
12
+ # process_tableXfields
13
+ # rubocop:disable Metrics/MethodLength
14
+ # rubocop:disable Metrics/AbcSize
15
+ def run(table, row, list)
12
16
  questions = []
13
- return questions unless type == 'text'
14
-
15
- if pTable.fields.count > 1
16
- questions = questions + process_table2fields(pTable, pRow, pList, 0, 1)
17
- elsif pTable.fields.count > 2
18
- questions = questions + process_table2fields(pTable, pRow, pList, 0, 2)
19
- # questions = questions + process_table2fields(pTable, pRow, pList, 1, 2)
20
- elsif pTable.fields.count > 3
21
- questions = questions + process_table2fields(pTable, pRow, pList, 0, 3)
22
- # questions = questions + process_table2fields(pTable, pRow, pList, 1, 3)
23
- # questions = questions + process_table2fields(pTable, pRow, pList, 2, 3)
17
+ return questions unless concept.type == 'text'
18
+
19
+ if table.fields.count == 2
20
+ questions += process_table2fields(table, row, list, 0, 1)
21
+ elsif table.fields.count == 3
22
+ questions += process_table2fields(table, row, list, 0, 1)
23
+ questions += process_table2fields(table, row, list, 0, 2)
24
+ elsif table.fields.count == 4
25
+ questions += process_table2fields(table, row, list, 0, 1)
26
+ questions += process_table2fields(table, row, list, 0, 2)
27
+ questions += process_table2fields(table, row, list, 0, 3)
24
28
  end
25
29
 
26
30
  questions
27
31
  end
32
+ # rubocop:enable Metrics/MethodLength
33
+ # rubocop:enable Metrics/AbcSize
34
+
35
+ private
28
36
 
29
- private
30
- def process_table2fields(lTable, lRow, pList, pCol1, pCol2)
37
+ # rubocop:disable Metrics/MethodLength
38
+ # rubocop:disable Metrics/AbcSize
39
+ # rubocop:disable Metrics/CyclomaticComplexity
40
+ # rubocop:disable Metrics/PerceivedComplexity
41
+ def process_table2fields(table, row, list, col1, col2)
31
42
  questions = []
43
+ lang = concept.lang
32
44
  # create questions
33
45
 
34
- # Using the column #0
35
- s = Set.new [ lRow[:data][0] , lang.text_for(:none) ]
36
- pList.each { |i| s.add( i[:data][0] ) }
46
+ # Question choice: Using the column #0
47
+ s = Set.new [row[:data][col1], lang.text_for(:none)]
48
+ list.each { |i| s.add(i[:data][col1]) }
37
49
  a = s.to_a
38
50
 
39
51
  if s.count > 3
40
- q=Question.new
41
- q.name="#{name}-#{num.to_s}-t1table-#{lTable.name}"
42
- q.text=lang.text_for(:t1table, name, lTable.fields[0].capitalize, lTable.fields[1].capitalize, lRow[:data][1])
43
- q.good=lRow[:data][0]
52
+ q = Question.new
53
+ q.name = "#{name}-#{num}-t1table-#{table.name}"
54
+ q.text = random_image_for(name) \
55
+ + lang.text_for(:t1table, name, table.fields[col1].capitalize, \
56
+ table.fields[col2].capitalize, row[:data][col2])
57
+ q.good = row[:data][col1]
44
58
  q.bads << lang.text_for(:none)
45
59
  q.bads << a[2]
46
60
  q.bads << a[3]
47
61
  questions << q
48
62
  end
49
63
 
50
- s = Set.new [ lRow[:data][0], lang.text_for(:none) ]
51
- pList.each { |i| s.add( i[:data][0] ) }
64
+ s = Set.new [row[:data][col1], lang.text_for(:none)]
65
+ list.each { |i| s.add(i[:data][col1]) }
52
66
  a = s.to_a
53
67
 
54
68
  if s.count > 4
55
69
  q = Question.new
56
- q.name = "#{name}-#{num.to_s}-t2table-#{lTable.name}"
57
- q.text = lang.text_for(:t2table, name, lTable.fields[0].capitalize, lTable.fields[1].capitalize, lRow[:data][1])
70
+ q.name = "#{name}-#{num}-t2table-#{table.name}"
71
+ q.text = random_image_for(name) \
72
+ + lang.text_for(:t2table, name, table.fields[col1].capitalize, \
73
+ table.fields[col2].capitalize, row[:data][col2])
58
74
  q.good = lang.text_for(:none)
59
75
  q.bads << a[2]
60
76
  q.bads << a[3]
@@ -62,15 +78,17 @@ private
62
78
  questions << q
63
79
  end
64
80
 
65
- # Using the column #1
66
- s = Set.new [ lRow[:data][1], lang.text_for(:none) ]
67
- pList.each { |i| s.add( i[:data][1] ) }
81
+ # Question choice: Using the column #1
82
+ s = Set.new [row[:data][col2], lang.text_for(:none)]
83
+ list.each { |i| s.add(i[:data][col2]) }
68
84
  a = s.to_a
69
85
 
70
86
  if s.count > 3
71
87
  q = Question.new
72
- q.name = "#{name}-#{num.to_s}-t3table-#{lTable.name}"
73
- q.text = lang.text_for(:t3table, name, lTable.fields[0].capitalize, lRow[:data][0], lTable.fields[1].capitalize)
88
+ q.name = "#{name}-#{num}-t3table-#{table.name}"
89
+ q.text = random_image_for(name) \
90
+ + lang.text_for(:t3table, name, table.fields[col1].capitalize, \
91
+ row[:data][col1], table.fields[col2].capitalize)
74
92
  q.good = a[0]
75
93
  q.bads << lang.text_for(:none)
76
94
  q.bads << a[2]
@@ -78,14 +96,16 @@ private
78
96
  questions << q
79
97
  end
80
98
 
81
- s = Set.new [ lRow[:data][1], lang.text_for(:none) ]
82
- pList.each { |i| s.add( i[:data][1] ) }
99
+ s = Set.new [row[:data][col2], lang.text_for(:none)]
100
+ list.each { |i| s.add(i[:data][col2]) }
83
101
  a = s.to_a
84
102
 
85
103
  if s.count > 4
86
104
  q = Question.new
87
- q.name = "#{name}-#{num.to_s}-t4table-#{lTable.name}"
88
- q.text = lang.text_for(:t4table, name, lTable.fields[0].capitalize, lRow[:data][0], lTable.fields[1].capitalize)
105
+ q.name = "#{name}-#{num}-t4table-#{table.name}"
106
+ q.text = random_image_for(name) \
107
+ + lang.text_for(:t4table, name, table.fields[col1].capitalize, \
108
+ row[:data][col1], table.fields[col2].capitalize)
89
109
  q.good = lang.text_for(:none)
90
110
  q.bads << a[2]
91
111
  q.bads << a[3]
@@ -93,78 +113,99 @@ private
93
113
  questions << q
94
114
  end
95
115
 
96
- # Boolean association TRUE
116
+ # Question Boolean: TRUE
97
117
  q = Question.new
98
118
  q.set_boolean
99
- q.name = "#{name}-#{num.to_s}t5table-#{lTable.name}"
100
- q.text = lang.text_for(:t5table, name, lTable.fields[0].capitalize, lRow[:data][0] ,lTable.fields[1].capitalize, lRow[:data][1] )
101
- q.good = "TRUE"
119
+ q.name = "#{name}-#{num}t5table-#{table.name}"
120
+ q.text = random_image_for(name) \
121
+ + lang.text_for(:t5table, name, table.fields[col1].capitalize, \
122
+ row[:data][col1], table.fields[col2].capitalize, row[:data][col2])
123
+ q.good = 'TRUE'
102
124
  questions << q
103
125
 
104
- # Boolean association FALSE
105
- s = Set.new [ lRow[:data][1] ]
106
- pList.each { |i| s.add( i[:data][1] ) }
126
+ # Question Boolean: FALSE
127
+ s = Set.new [row[:data][col2]]
128
+ list.each { |i| s.add(i[:data][col2]) }
107
129
  a = s.to_a
108
130
 
109
131
  if s.count > 1
110
132
  q = Question.new
111
133
  q.set_boolean
112
- q.name = "#{name}-#{num.to_s}-t6table-#{lTable.name}"
113
- q.text = lang.text_for(:t6table, name, lTable.fields[0].capitalize, lRow[:data][0], lTable.fields[1].capitalize, a[1] )
114
- q.good = "FALSE"
134
+ q.name = "#{name}-#{num}-t6table-#{table.name}"
135
+ q.text = random_image_for(name) \
136
+ + lang.text_for(:t6table, name, table.fields[col1].capitalize, \
137
+ row[:data][col1], table.fields[col2].capitalize, a[1])
138
+ q.good = 'FALSE'
115
139
  questions << q
116
140
  end
117
141
 
118
- s = Set.new [ lRow[:data][0] ]
119
- pList.each { |i| s.add( i[:data][0] ) }
142
+ s = Set.new [row[:data][col1]]
143
+ list.each { |i| s.add(i[:data][col1]) }
120
144
  a = s.to_a
121
145
 
122
146
  if s.count > 1
123
147
  q = Question.new
124
148
  q.set_boolean
125
- q.name = "#{name}-#{num.to_s}t7table-#{lTable.name}"
126
- q.text = lang.text_for(:t7table, name, lTable.fields[0].capitalize, a[1], lTable.fields[1].capitalize, lRow[:data][1] )
127
- q.good = "FALSE"
149
+ q.name = "#{name}-#{num}t7table-#{table.name}"
150
+ q.text = random_image_for(name) \
151
+ + lang.text_for(:t7table, name, table.fields[col1].capitalize, \
152
+ a[1], table.fields[col2].capitalize, row[:data][col2])
153
+ q.good = 'FALSE'
128
154
  questions << q
129
155
  end
130
156
 
131
- # Short answer with column #0, 1 word
132
- if lang.count_words(lRow[:data][0]) == 1
157
+ # Question Short: column #0, 1 word
158
+ if lang.count_words(row[:data][col1]) == 1
133
159
  q = Question.new
134
160
  q.set_short
135
- q.name = "#{name}-#{num.to_s}t8table-#{lTable.name}"
136
- q.text = lang.text_for(:t8table, name, lTable.fields[1].capitalize, lRow[:data][1], lTable.fields[0].capitalize)
137
- q.shorts << lRow[:data][0]
138
- q.shorts << lRow[:data][0].gsub('-', ' ').gsub('_', ' ')
161
+ q.name = "#{name}-#{num}t8table-#{table.name}"
162
+ q.text = random_image_for(name) \
163
+ + lang.text_for(:t8table, name, table.fields[col2].capitalize, \
164
+ row[:data][col2], table.fields[col1].capitalize)
165
+ q.shorts << row[:data][col1]
166
+ q.shorts << row[:data][col1].gsub('-', ' ').gsub('_', ' ')
139
167
  questions << q
140
- elsif lang.count_words(lRow[:data][0]) == 2
168
+ elsif lang.count_words(row[:data][col1]) == 2
141
169
  q = Question.new
142
170
  q.set_short
143
- q.name = "#{name}-#{num.to_s}t9table-#{lTable.name}"
144
- q.text = lang.text_for(:t9table, name, lTable.fields[1].capitalize, lRow[:data][1], lTable.fields[0].capitalize, "[#{lang.hide_text(lRow[:data][0])}]", lang.count_words(lRow[:data][0]) )
145
- q.shorts << lRow[:data][0]
146
- q.shorts << lRow[:data][0].gsub('-', ' ').gsub('_', ' ')
171
+ q.name = "#{name}-#{num}t9table-#{table.name}"
172
+ q.text = random_image_for(name) \
173
+ + lang.text_for(:t9table, name, table.fields[col2].capitalize, \
174
+ row[:data][col2], table.fields[col1].capitalize, \
175
+ "[#{lang.hide_text(row[:data][col1])}]", lang.count_words(row[:data][col1]))
176
+ q.shorts << row[:data][col1]
177
+ q.shorts << row[:data][col1].gsub('-', ' ').gsub('_', ' ')
147
178
  questions << q
148
179
  end
149
180
 
150
- # Short answer with column #1, 1 word
151
- if lang.count_words(lRow[:data][1]) == 1
181
+ # Question Short: column #1, 1 word
182
+ if lang.count_words(row[:data][col2]) == 1
152
183
  q = Question.new
153
184
  q.set_short
154
- q.name = "#{name}-#{num.to_s}t8table-#{lTable.name}"
155
- q.text = lang.text_for(:t8table, name, lTable.fields[0].capitalize, lRow[:data][0], lTable.fields[1].capitalize)
156
- q.shorts << lRow[:data][1]
157
- q.shorts << lRow[:data][1].gsub('-', ' ').gsub('_', ' ')
185
+ q.name = "#{name}-#{num}t8table-#{table.name}"
186
+ q.text = random_image_for(name) \
187
+ + lang.text_for(:t8table, name, table.fields[col1].capitalize, \
188
+ row[:data][col1], table.fields[col2].capitalize)
189
+ q.shorts << row[:data][col2]
190
+ q.shorts << row[:data][col2].gsub('-', ' ').gsub('_', ' ')
158
191
  questions << q
159
- elsif lang.count_words(lRow[:data][1]) == 2
192
+ elsif lang.count_words(row[:data][col2]) == 2
160
193
  q = Question.new
161
194
  q.set_short
162
- q.name = "#{name}-#{num.to_s}t9table-#{lTable.name}"
163
- q.text = lang.text_for(:t9table, name, lTable.fields[0].capitalize, lRow[:data][0], lTable.fields[1].capitalize, "[#{lang.hide_text(lRow[:data][1])}]", lang.count_words(lRow[:data][1]) )
164
- q.shorts << lRow[:data][1]
165
- q.shorts << lRow[:data][1].gsub('-', ' ').gsub('_', ' ')
195
+ q.name = "#{name}-#{num}t9table-#{table.name}"
196
+ q.text = random_image_for(name) \
197
+ + lang.text_for(:t9table, name, table.fields[col1].capitalize, \
198
+ row[:data][col1], table.fields[col2].capitalize, \
199
+ "[#{lang.hide_text(row[:data][col2])}]", lang.count_words(row[:data][col2]))
200
+ q.shorts << row[:data][col2]
201
+ q.shorts << row[:data][col2].gsub('-', ' ').gsub('_', ' ')
166
202
  questions << q
167
203
  end
168
204
  questions
169
205
  end
206
+ # rubocop:enable Metrics/MethodLength
207
+ # rubocop:enable Metrics/AbcSize
208
+ # rubocop:enable Metrics/CyclomaticComplexity
209
+ # rubocop:enable Metrics/PerceivedComplexity
170
210
  end
211
+ # rubocop:enable Metrics/ClassLength
@@ -8,9 +8,11 @@ require 'rainbow'
8
8
  class Application
9
9
  include Singleton
10
10
 
11
- VERSION = '2.1.7' # Application version
12
- NAME = 'asker' # Application name
13
- GEM = 'asker-tool' # Gem name
11
+ VERSION = '2.2.0' # Application version
12
+ NAME = 'asker' # Application name
13
+ HOMEPAGE = "https://github.com/dvarrui/#{NAME}/tree/v2.2"
14
+ GEM = 'asker-tool' # Gem name
15
+ CONFIGFILE = 'asker.ini' # Config filename
14
16
  attr_reader :config
15
17
 
16
18
  ##
@@ -24,10 +26,9 @@ class Application
24
26
  # rubocop:disable Metrics/AbcSize
25
27
  # rubocop:disable Metrics/MethodLength
26
28
  def reset
27
- filename = File.join(Dir.pwd, 'config.ini')
28
- unless File.exist? filename
29
- filename = File.join(File.dirname(__FILE__), 'files', 'config.ini')
30
- end
29
+ filename = File.join(Dir.pwd, CONFIGFILE)
30
+ filename = File.join(File.dirname(__FILE__), 'files', CONFIGFILE) unless File.exist? filename
31
+
31
32
  begin
32
33
  @config = IniFile.load(filename)
33
34
  rescue StandardError => e
data/lib/asker/checker.rb CHANGED
@@ -131,6 +131,7 @@ module Checker
131
131
  end
132
132
 
133
133
  # rubocop:disable Metrics/MethodLength
134
+ # rubocop:disable Metrics/AbcSize
134
135
  def check_map(line, index)
135
136
  if index.zero?
136
137
  @outputs[index][:type] = :map
@@ -147,8 +148,10 @@ module Checker
147
148
  end
148
149
  end
149
150
  # rubocop:enable Metrics/MethodLength
151
+ # rubocop:enable Metrics/AbcSize
150
152
 
151
153
  # rubocop:disable Metrics/MethodLength
154
+ # rubocop:disable Metrics/AbcSize
152
155
  def check_concept(line, index)
153
156
  return unless @outputs[index][:state] == :none
154
157
  return unless line.include? '%concept'
@@ -165,6 +168,7 @@ module Checker
165
168
  end
166
169
  end
167
170
  # rubocop:enable Metrics/MethodLength
171
+ # rubocop:enable Metrics/AbcSize
168
172
 
169
173
  # rubocop:disable Metrics/AbcSize
170
174
  # rubocop:disable Metrics/MethodLength
@@ -247,9 +251,7 @@ module Checker
247
251
  # rubocop:enable Metrics/MethodLength
248
252
 
249
253
  # rubocop:disable Metrics/AbcSize
250
- # rubocop:disable Metrics/CyclomaticComplexity
251
254
  # rubocop:disable Metrics/MethodLength
252
- # rubocop:disable Metrics/PerceivedComplexity
253
255
  def check_row(line, index)
254
256
  return unless @outputs[index][:state] == :none
255
257
  return unless line.include? '%row'
@@ -276,14 +278,10 @@ module Checker
276
278
  end
277
279
  end
278
280
  # rubocop:enable Metrics/AbcSize
279
- # rubocop:enable Metrics/CyclomaticComplexity
280
281
  # rubocop:enable Metrics/MethodLength
281
- # rubocop:enable Metrics/PerceivedComplexity
282
282
 
283
283
  # rubocop:disable Metrics/AbcSize
284
- # rubocop:disable Metrics/CyclomaticComplexity
285
284
  # rubocop:disable Metrics/MethodLength
286
- # rubocop:disable Metrics/PerceivedComplexity
287
285
  def check_col(line, index)
288
286
  return unless @outputs[index][:state] == :none
289
287
  return unless line.include? '%col'
@@ -309,9 +307,7 @@ module Checker
309
307
  check_text(line, index)
310
308
  end
311
309
  # rubocop:enable Metrics/AbcSize
312
- # rubocop:enable Metrics/CyclomaticComplexity
313
310
  # rubocop:enable Metrics/MethodLength
314
- # rubocop:enable Metrics/PerceivedComplexity
315
311
 
316
312
  def check_text(line, index)
317
313
  return unless @outputs[index][:state] == :ok
@@ -347,6 +343,7 @@ module Checker
347
343
  # rubocop:enable Metrics/MethodLength
348
344
 
349
345
  # rubocop:disable Metrics/MethodLength
346
+ # rubocop:disable Metrics/AbcSize
350
347
  def check_code(line, index)
351
348
  return unless @outputs[index][:state] == :none
352
349
  return unless line.include? '%code'
@@ -363,6 +360,7 @@ module Checker
363
360
  end
364
361
  end
365
362
  # rubocop:enable Metrics/MethodLength
363
+ # rubocop:enable Metrics/AbcSize
366
364
 
367
365
  # rubocop:disable Metrics/MethodLength
368
366
  # rubocop:disable Metrics/AbcSize
data/lib/asker/cli.rb CHANGED
@@ -15,24 +15,24 @@ 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
23
  long_desc <<-LONGDESC
25
- Create output files, from input file (HAML/XML format).
26
24
 
27
25
  Build questions about contents defined into input file specified.
28
26
 
27
+ Create output files, from input file (HAML/XML format).
28
+
29
29
  Examples:
30
30
 
31
- (1) #{Rainbow('asker input/foo/foo.haml').yellow}, Build questions from HAML file.
31
+ (1) #{Rainbow('asker input/foo/foo.haml').aqua}, Build questions from HAML file.
32
32
 
33
- (2) #{Rainbow('asker input/foo/foo.xml').yellow}, Build questions from XML file.
33
+ (2) #{Rainbow('asker input/foo/foo.xml').aqua}, Build questions from XML file.
34
34
 
35
- (3) #{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.
36
36
 
37
37
  LONGDESC
38
38
  ##
@@ -55,16 +55,24 @@ class CLI < Thor
55
55
  Asker.check(filename)
56
56
  end
57
57
 
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
+
58
66
  map ['i', '-i', '--init'] => 'init'
59
- desc 'init', 'Create default INI config fie'
67
+ desc 'init', 'Create default INI config file'
60
68
  ##
61
69
  # Create default INI config file
62
70
  def init
63
71
  Asker.create_configuration
64
72
  end
65
73
 
66
- map ['n', '-b', '--new', 'new'] => 'create_input'
67
- desc 'new', 'Create Asker demo input files'
74
+ map ['n', '-n', '--new', 'new'] => 'create_input'
75
+ desc 'new [FOLDER]', 'Create Asker demo input files'
68
76
  ##
69
77
  # Create Asker demo input files
70
78
  # @param dirname (String) Path to folder
@@ -79,4 +87,14 @@ class CLI < Thor
79
87
  def method_missing(method, *_args, &_block)
80
88
  file(method.to_s)
81
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
82
100
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../ai/code/code_ai_factory'
2
4
  require_relative '../project'
3
5
  require_relative '../logger'
@@ -46,6 +48,7 @@ class Code
46
48
 
47
49
  def load(filepath)
48
50
  return if filepath.nil?
51
+
49
52
  unless File.exist? filepath
50
53
  Logger.verboseln Rainbow("[ERROR] Unkown file #{filepath}").red.bright
51
54
  return
@@ -56,7 +59,7 @@ class Code
56
59
 
57
60
  def encode_and_split(text, encoding = :default)
58
61
  # Convert text to UTF-8 deleting unknown chars
59
- text = text || '' # Ensure text is not nil
62
+ text ||= '' # Ensure text is not nil
60
63
  flag = [:default, 'UTF-8'].include? encoding
61
64
  return text.encode('UTF-8', invalid: :replace).split("\n") if flag
62
65