asker-tool 2.1.3 → 2.2.0

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.
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
@@ -1,18 +1,31 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'set'
3
4
 
4
5
  # Define Question class
5
6
  class Question
6
- attr_accessor :name, :comment, :text
7
- attr_accessor :good, :bads, :matching, :shorts
8
- attr_accessor :feedback
9
- attr_reader :type
10
- attr_accessor :tags, :lang
7
+ attr_accessor :name # Question name used as identification
8
+ attr_accessor :comment # Comments asociated
9
+ attr_accessor :text # The real text of the question
10
+ attr_accessor :good # The correct answer
11
+ attr_accessor :bads # Bads answers used by choice type question
12
+ attr_accessor :matching # Matching answers used by match type question
13
+ attr_accessor :shorts # Short answers used by short type question
14
+ attr_accessor :feedback # Question feedbak
15
+ attr_reader :type # Question type: :choice, :match, :boolean, :short
16
+ attr_accessor :tags
17
+ attr_accessor :lang # Info used when export (YAML)
18
+ attr_accessor :encode # image base64 content used when export Moodle xml
11
19
 
20
+ # Initialize object
21
+ # @param type (Symbol) Question type: choice, match, boolean, short
12
22
  def initialize(type = :choice)
13
23
  reset(type)
14
24
  end
15
25
 
26
+ # Reset attributes
27
+ # @param type (Symbol) Question type: choice, match, boolean, short
28
+ # rubocop:disable Metrics/MethodLength
16
29
  def reset(type = :choice)
17
30
  @name = ''
18
31
  @comment = ''
@@ -26,32 +39,41 @@ class Question
26
39
  shuffle_on
27
40
  @tags = Set.new
28
41
  @lang = nil
42
+ @encode = :none
29
43
  end
44
+ # rubocop:enable Metrics/MethodLength
30
45
 
46
+ # Set choice type
31
47
  def set_choice
32
48
  @type = :choice
33
49
  end
34
50
 
51
+ # Set match type
35
52
  def set_match
36
53
  @type = :match
37
54
  end
38
55
 
56
+ # Set boolean type
39
57
  def set_boolean
40
58
  @type = :boolean
41
59
  end
42
60
 
61
+ # Set short type
43
62
  def set_short
44
63
  @type = :short
45
64
  end
46
65
 
66
+ # Set shuffle off
47
67
  def shuffle_off
48
68
  @shuffle = false
49
69
  end
50
70
 
71
+ # Set shuffle on
51
72
  def shuffle_on
52
73
  @shuffle = true
53
74
  end
54
75
 
76
+ # Return shuffle value
55
77
  def shuffle?
56
78
  @shuffle
57
79
  end
@@ -1,16 +1,55 @@
1
+ # frozen_string_literal: true
1
2
 
3
+ # Base Stage class
2
4
  class BaseStage
5
+ #
6
+ # Initialize Stage with ConceptAI
7
+ # @param concept_ai (ConceptAI)
3
8
  def initialize(concept_ai)
4
9
  @concept_ai = concept_ai
5
10
  end
6
11
 
7
- # If a method we call is missing, pass the call onto
8
- # the object we delegate to.
9
- def method_missing(m, *args, &block)
10
- @concept_ai.send(m, *args, &block)
11
- end
12
-
13
12
  def run
14
13
  raise 'Implement run method!'
15
14
  end
15
+
16
+ def concept
17
+ @concept_ai.concept
18
+ end
19
+
20
+ def name(option = :raw)
21
+ @concept_ai.concept.name(option)
22
+ end
23
+
24
+ def names
25
+ raise 'Change names by concept.names'
26
+ end
27
+
28
+ def num
29
+ @concept_ai.num
30
+ end
31
+
32
+ def lang
33
+ raise 'Change lang by concept.lang'
34
+ end
35
+
36
+ def type
37
+ raise 'Change type by concept.type'
38
+ end
39
+
40
+ def texts
41
+ raise 'Change texts by cocept.texts'
42
+ end
43
+
44
+ def images
45
+ raise 'Change images by cocept.images'
46
+ end
47
+
48
+ def neighbors
49
+ raise 'Change neighbors by concept.neighbors'
50
+ end
51
+
52
+ def random_image_for(option)
53
+ @concept_ai.random_image_for(option)
54
+ end
16
55
  end
@@ -1,87 +1,137 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'set'
4
4
 
5
5
  require_relative 'base_stage'
6
6
  require_relative '../question'
7
7
 
8
+ ##
9
+ # range b1
8
10
  class StageB < BaseStage
9
- # range b1
10
-
11
- def run(pTable, pList1, pList2)
12
- # process table match
11
+ ##
12
+ # Process table data to generate match questions
13
+ # @param table (Table)
14
+ # @param list1 (Array) Rows that belong to this table
15
+ # @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
+ def run(table, list1, list2)
13
19
  questions = []
14
- return questions if pTable.fields.count < 2
20
+ return questions if table.fields.count < 2
15
21
 
16
- return questions unless type == 'text'
22
+ return questions unless concept.type == 'text'
17
23
 
18
- if pTable.fields.count>1 then
19
- questions += process_table_match2fields(pTable, pList1, pList2, 0, 1)
20
- elsif pTable.fields.count>2 then
21
- questions += process_table_match2fields(pTable, pList1, pList2, 0, 2)
22
- questions += process_table_match2fields(pTable, pList1, pList2, 1, 2)
23
- elsif pTable.fields.count>3 then
24
- questions += process_table_match2fields(pTable, pList1, pList2, 0, 3)
25
- questions += process_table_match2fields(pTable, pList1, pList2, 1, 3)
26
- questions += process_table_match2fields(pTable, pList1, pList2, 2, 3)
24
+ if table.fields.count == 2
25
+ questions += process_table_match2fields(table, list1, list2, 0, 1)
26
+ elsif table.fields.count == 3
27
+ questions += process_table_match2fields(table, list1, list2, 0, 1)
28
+ questions += process_table_match2fields(table, list1, list2, 0, 2)
29
+ elsif table.fields.count == 4
30
+ questions += process_table_match2fields(table, list1, list2, 0, 1)
31
+ questions += process_table_match2fields(table, list1, list2, 0, 2)
32
+ questions += process_table_match2fields(table, list1, list2, 0, 3)
27
33
  end
28
34
 
29
35
  questions
30
36
  end
37
+ # rubocop:enable Metrics/AbcSize
38
+ # rubocop:enable Metrics/MethodLength
31
39
 
32
- def process_table_match2fields(pTable, pList1, pList2, pIndex1, pIndex2)
40
+ ##
41
+ # Process table data to generate match questions
42
+ # @param p_table (Table)
43
+ # @param list1 (Array) Rows that belong to this table
44
+ # @param list2 (Array) List with similar rows (same table name) from the neighbours tables
45
+ # @param index1 (Integer) Use this field number
46
+ # @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
+ def process_table_match2fields(p_table, list1, list2, index1, index2)
33
54
  questions = []
55
+ lang = concept.lang
34
56
 
35
- if pList1.count>3
36
- pList1.each_cons(4) do |e1,e2,e3,e4|
37
- e = [ e1, e2, e3, e4 ]
57
+ if list1.count > 3
58
+ list1.each_cons(4) do |e1, e2, e3, e4|
59
+ e = [e1, e2, e3, e4]
38
60
 
39
- #Question type <b1match>: match 4 items from the same table
61
+ # Question type <b1match>: match 4 items from the same table
40
62
  e.shuffle!
41
- q=Question.new(:match)
42
- q.name="#{name}-#{num.to_s}-b1match4x4-#{pTable.name}"
43
- q.text= random_image_for(name) + lang.text_for(:b1, name, pTable.fields[pIndex1].capitalize, pTable.fields[pIndex2].capitalize )
44
- q.matching << [ e[0][:data][pIndex1], e[0][:data][pIndex2] ]
45
- q.matching << [ e[1][:data][pIndex1], e[1][:data][pIndex2] ]
46
- q.matching << [ e[2][:data][pIndex1], e[2][:data][pIndex2] ]
47
- q.matching << [ e[3][:data][pIndex1], e[3][:data][pIndex2] ]
63
+ q = Question.new(:match)
64
+ q.name = "#{name}-#{num}-b1match4x4-#{p_table.name}"
65
+ q.tags << 'match'
66
+ q.tags << 'random'
67
+ q.text = random_image_for(name) \
68
+ + lang.text_for(:b1, name, p_table.fields[index1].capitalize, p_table.fields[index2].capitalize)
69
+ q.matching << [e[0][:data][index1], e[0][:data][index2]]
70
+ q.matching << [e[1][:data][index1], e[1][:data][index2]]
71
+ q.matching << [e[2][:data][index1], e[2][:data][index2]]
72
+ q.matching << [e[3][:data][index1], e[3][:data][index2]]
73
+ # Add an extra line
74
+ if list2.count.positive?
75
+ q.matching << ['', list2[0][:data][index2]]
76
+ else
77
+ q.tags << 'misspell'
78
+ q.matching << ['', lang.do_mistake_to(e[0][:data][index2])]
79
+ end
48
80
  questions << q
49
81
 
50
82
  # Question type <b1match>: match 3 items from table-A and 1 item with error
51
83
  e.shuffle!
52
- q=Question.new(:match)
53
- q.name="#{name}-#{num.to_s}-b1match3x1misspelled-#{pTable.name}"
54
- q.text= random_image_for(name) + lang.text_for(:b1, name, pTable.fields[pIndex1].capitalize, pTable.fields[pIndex2].capitalize )
55
- q.matching << [ e[0][:data][pIndex1], e[0][:data][pIndex2] ]
56
- q.matching << [ e[1][:data][pIndex1], e[1][:data][pIndex2] ]
57
- q.matching << [ e[2][:data][pIndex1], e[2][:data][pIndex2] ]
58
- q.matching << [ lang.do_mistake_to(e[3][:data][pIndex1]), lang.text_for(:misspelling) ]
84
+ q = Question.new(:match)
85
+ q.name = "#{name}-#{num}-b1match3x1misspelled-#{p_table.name}"
86
+ q.tags << 'match'
87
+ q.tags << 'random'
88
+ q.text = random_image_for(name) \
89
+ + lang.text_for(:b1, name, p_table.fields[index1].capitalize, p_table.fields[index2].capitalize)
90
+ q.matching << [e[0][:data][index1], e[0][:data][index2]]
91
+ q.matching << [e[1][:data][index1], e[1][:data][index2]]
92
+ q.matching << [e[2][:data][index1], e[2][:data][index2]]
93
+ q.matching << [lang.do_mistake_to(e[3][:data][index1]), lang.text_for(:misspelling)]
94
+ # Add an extra line
95
+ if list2.count.positive?
96
+ q.matching << ['', list2[0][:data][index2]]
97
+ else
98
+ q.tags << 'misspell'
99
+ q.matching << ['', lang.do_mistake_to(e[0][:data][index2])]
100
+ end
59
101
  questions << q
60
102
  end
61
103
  end
62
104
 
63
- if pList1.count>2 and pList2.count>0
64
- s=Set.new
65
- pList1.each do |i|
66
- s.add( i[:data][pIndex1]+"<=>"+i[:data][pIndex2] )
105
+ if list1.count > 2 && list2.count.positive?
106
+ s = Set.new
107
+ list1.each do |i|
108
+ s.add(i[:data][index1] + '<=>' + i[:data][index2])
67
109
  end
68
- s.add( pList2[0][:data][pIndex1]+"<=>"+pList2[0][:data][pIndex2] )
69
- a=s.to_a
110
+ s.add(list2[0][:data][index1] + '<=>' + list2[0][:data][index2])
70
111
 
71
112
  # Question 3 items from table-A, and 1 item from table-B
72
113
  if s.count > 3
73
- q=Question.new(:match)
74
- q.name="#{name}-#{num.to_s}-b1match3x1-#{pTable.name}"
75
- q.text= random_image_for(name) + lang.text_for(:b1, name , pTable.fields[pIndex1].capitalize, pTable.fields[pIndex2].capitalize)
76
- q.matching << [ pList1[0][:data][pIndex1], pList1[0][:data][pIndex2] ]
77
- q.matching << [ pList1[1][:data][pIndex1], pList1[1][:data][pIndex2] ]
78
- q.matching << [ pList1[2][:data][pIndex1], pList1[2][:data][pIndex2] ]
79
- q.matching << [ pList2[0][:data][pIndex1], lang.text_for(:error) ]
114
+ q = Question.new(:match)
115
+ q.name = "#{name}-#{num}-b1match3x1-#{p_table.name}"
116
+ q.tags << 'match'
117
+ q.tags << 'random'
118
+ q.text = random_image_for(name) \
119
+ + lang.text_for(:b1, name, p_table.fields[index1].capitalize, p_table.fields[index2].capitalize)
120
+ q.matching << [list1[0][:data][index1], list1[0][:data][index2]]
121
+ q.matching << [list1[1][:data][index1], list1[1][:data][index2]]
122
+ q.matching << [list1[2][:data][index1], list1[2][:data][index2]]
123
+ q.matching << [list2[0][:data][index1], lang.text_for(:error)]
124
+ q.matching << ['', lang.do_mistake_to(list1[0][:data][index2])]
80
125
  questions << q
81
126
  end
82
127
  end
83
128
 
84
- return questions
129
+ questions
85
130
  end
86
-
131
+ # rubocop:enable Metrics/AbcSize
132
+ # rubocop:enable Metrics/MethodLength
133
+ # rubocop:enable Metrics/CyclomaticComplexity
134
+ # rubocop:enable Style/ConditionalAssignment
135
+ # rubocop:enable Metrics/BlockLength
136
+ # rubocop:enable Metrics/PerceivedComplexity
87
137
  end
@@ -1,160 +1,145 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'set'
4
4
 
5
5
  require_relative 'base_stage'
6
6
  require_relative '../question'
7
7
 
8
+ # range d1-d4
8
9
  class StageD < BaseStage
9
- # range d1-d4
10
-
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
11
16
  def run
12
17
  # Stage D: process every definition, I mean every <def> tag
13
18
  questions = []
14
- return questions unless type == 'text'
19
+ return questions unless concept.type == 'text'
15
20
 
21
+ lang = concept.lang
16
22
  # for every <text> do this
17
- texts.each do |t|
18
- s=Set.new [name(:raw), lang.text_for(:none)]
19
- neighbors.each { |n| s.add n[:concept].name(:decorated) }
20
- a=s.to_a
23
+ concept.texts.each do |t|
24
+ s = Set.new [name(:raw), lang.text_for(:none)]
25
+ concept.neighbors.each { |n| s.add n[:concept].name(:decorated) }
26
+ a = s.to_a
21
27
 
22
28
  # Question choose between 4 options
23
29
  if s.count > 3
24
- q=Question.new(:choice)
25
- q.name="#{name(:id)}-#{num}-d1choose"
26
- q.text=random_image_for(name(:raw)) + lang.text_for(:d1,t)
27
- q.good=name(:raw)
30
+ q = Question.new(:choice)
31
+ q.name = "#{name(:id)}-#{num}-d1choose"
32
+ q.text = random_image_for(name(:raw)) + lang.text_for(:d1, t)
33
+ q.good = name(:raw)
28
34
  q.bads << lang.text_for(:none)
29
35
  q.bads << a[2]
30
36
  q.bads << a[3]
31
37
  questions << q
32
38
  end
33
39
 
34
- #Question choose between 4 options, good none (Syntax error)
35
- if s.count>3 and type=="text" then
36
- q=Question.new(:choice)
37
- q.name="#{name(:id)}-#{num}-d1none-misspelled"
38
- q.text=random_image_for(name(:raw)) + lang.text_for(:d1,t)
40
+ # Question choose between 4 options, good none (Syntax error)
41
+ if s.count > 3
42
+ q = Question.new(:choice)
43
+ q.name = "#{name(:id)}-#{num}-d1none-misspelled"
44
+ q.text = random_image_for(name(:raw)) + lang.text_for(:d1, t)
39
45
  q.good = lang.text_for(:none)
40
46
  q.bads << lang.do_mistake_to(name(:raw))
41
47
  q.bads << a[2]
42
48
  q.bads << a[3]
43
- q.feedback="Option misspelled!: #{name(:raw)}"
49
+ q.feedback = "Option misspelled!: #{name(:raw)}"
44
50
  questions << q
45
51
  end
46
52
 
47
53
  s.delete(name(:raw))
48
- a=s.to_a
54
+ a = s.to_a
49
55
 
50
- #Question choose between 4 options, good none
51
- if s.count>3 then
56
+ # Question choose between 4 options, good none
57
+ if s.count > 3
52
58
  q = Question.new(:choice)
53
- q.name="#{name(:id)}-#{num}-d1none"
54
- q.text=random_image_for(name(:raw)) + lang.text_for(:d1,t)
55
- q.good=lang.text_for(:none)
59
+ q.name = "#{name(:id)}-#{num}-d1none"
60
+ q.text = random_image_for(name(:raw)) + lang.text_for(:d1, t)
61
+ q.good = lang.text_for(:none)
56
62
  q.bads << a[1]
57
63
  q.bads << a[2]
58
64
  q.bads << a[3]
59
65
  questions << q
60
66
  end
61
67
 
62
- #Question boolean => TRUE
63
- #q = Question.new(:boolean)
64
- #q.name="#{name}-#{num}-d2true"
65
- #q.text=random_image_for(name) + lang.text_for(:d2,name,t)
66
- #q.good="TRUE"
67
- #questions << q
68
-
68
+ # Question choice => mispelled
69
69
  q = Question.new(:choice)
70
- q.name="#{name(:id)}-#{num}-d2def-mispelled"
71
- q.text=random_image_for(name(:raw)) + lang.text_for(:d2,name(:decorated), lang.do_mistake_to(t) )
72
- q.good=lang.text_for(:misspelling)
70
+ q.name = "#{name(:id)}-#{num}-d2def-mispelled"
71
+ q.text = random_image_for(name(:raw)) + lang.text_for(:d2, name(:decorated), lang.do_mistake_to(t))
72
+ q.good = lang.text_for(:misspelling)
73
73
  q.bads << lang.text_for(:true)
74
74
  q.bads << lang.text_for(:false)
75
- q.feedback="Definition text mispelled!: #{t}"
75
+ q.feedback = "Definition text mispelled!: #{t}"
76
76
  questions << q
77
77
 
78
- if type=="text"
79
- q = Question.new(:choice)
80
- q.name="#{name(:id)}-#{num}-d2name-mispelled"
81
- q.text=random_image_for(name(:raw)) + lang.text_for(:d2, lang.do_mistake_to(name(:raw)), t)
82
- q.good=lang.text_for(:misspelling)
83
- q.bads << lang.text_for(:true)
84
- q.bads << lang.text_for(:false)
85
- q.feedback="Concept name mispelled!: #{name(:raw)}"
86
- questions << q
87
- end
78
+ # Question choice => name mispelled
79
+ q = Question.new(:choice)
80
+ q.name = "#{name(:id)}-#{num}-d2name-mispelled"
81
+ q.text = random_image_for(name(:raw)) + lang.text_for(:d2, lang.do_mistake_to(name(:raw)), t)
82
+ q.good = lang.text_for(:misspelling)
83
+ q.bads << lang.text_for(:true)
84
+ q.bads << lang.text_for(:false)
85
+ q.feedback = "Concept name mispelled!: #{name(:raw)}"
86
+ questions << q
88
87
 
88
+ # Question choice => true
89
89
  q = Question.new(:choice)
90
- q.name="#{name(:id)}-#{num}-d2true"
91
- q.text=random_image_for(name(:raw)) + lang.text_for(:d2, name(:raw), t )
90
+ q.name = "#{name(:id)}-#{num}-d2true"
91
+ q.text = random_image_for(name(:raw)) + lang.text_for(:d2, name(:raw), t)
92
92
  q.good = lang.text_for(:true)
93
93
  q.bads << lang.text_for(:misspelling)
94
94
  q.bads << lang.text_for(:false)
95
95
  questions << q
96
96
 
97
- if a.size>1 then
97
+ # Question choice => false
98
+ if a.size > 1
98
99
  q = Question.new(:choice)
99
- q.name="#{name(:id)}-#{num}-d2false-misspelled"
100
- q.text=random_image_for(name(:raw)) + lang.text_for(:d2, a[1], t)
100
+ q.name = "#{name(:id)}-#{num}-d2false-misspelled"
101
+ q.text = random_image_for(name(:raw)) + lang.text_for(:d2, a[1], t)
101
102
  q.good = lang.text_for(:false)
102
103
  q.bads << lang.text_for(:misspelling)
103
104
  q.bads << lang.text_for(:true)
104
105
  questions << q
105
106
  end
106
107
 
107
- #Question type <a4desc>: boolean => FALSE
108
- #if neighbors.count>0 then
109
- # q = Question.new(:boolean)
110
- # q.name="#{name}-#{num}-d2false"
111
- # q.text=random_image_for(name) + lang.text_for(:d2, neighbors[0][:concept].name, t)
112
- # q.good="FALSE"
113
- # questions << q
114
- #end
115
-
116
- if type=="text"
117
- #Question hidden name questions
118
- q = Question.new(:short)
119
- q.name="#{name(:id)}-#{num}-d3hidden"
120
- q.text=random_image_for(name(:raw)) + lang.text_for(:d3, lang.hide_text(name(:raw)), t )
121
- q.shorts << name(:raw)
122
- q.shorts << name(:raw).gsub("-"," ").gsub("_"," ")
123
- names.each do |n|
124
- q.shorts << n if n!=name
125
- end
126
- questions << q
127
- end
128
-
129
- # indexes = []
130
- # exclude = ["[", "]", "(", ")", "\"" ]
131
- # filtered[:words].each_with_index do |item,index|
132
- # flag=true
133
- # exclude.each { |e| flag=false if (item[:word].include?(e)) }
134
- # indexes << index if flag
135
- # end
108
+ # Question hidden name questions
109
+ q = Question.new(:short)
110
+ q.name = "#{name(:id)}-#{num}-d3hidden"
111
+ q.text = random_image_for(name(:raw)) + lang.text_for(:d3, lang.hide_text(name(:raw)), t)
112
+ q.shorts << name(:raw)
113
+ q.shorts << name(:raw).gsub('-', ' ').gsub('_', ' ')
114
+ concept.names.each { |n| q.shorts << n if n != name }
115
+ questions << q
136
116
 
137
- #Question filtered text questions
138
- filtered=lang.text_with_connectors(t)
117
+ # Question filtered text questions
118
+ filtered = lang.text_with_connectors(t)
139
119
  indexes = filtered[:indexes]
140
120
 
141
- groups = (indexes.combination(4).to_a).shuffle
142
- max = (indexes.size/4).to_i
143
- groups[0,max].each do |e|
121
+ groups = indexes.combination(4).to_a.shuffle
122
+ max = (indexes.size / 4).to_i
123
+ groups[0, max].each do |e|
144
124
  e.sort!
145
125
  q = Question.new(:match)
146
126
  q.shuffle_off
147
127
  q.name = "#{name}-#{num}-d4filtered"
148
- s = lang.build_text_from_filtered( filtered, e)
149
- q.text = random_image_for(name(:raw)) + lang.text_for(:d4, name(:raw) , s)
150
- e.each_with_index do |value,index|
151
- q.matching << [ (index+1).to_s, filtered[:words][value][:word].downcase ]
128
+ s = lang.build_text_from_filtered(filtered, e)
129
+ q.text = random_image_for(name(:raw)) + lang.text_for(:d4, name(:raw), s)
130
+ e.each_with_index do |value, index|
131
+ q.matching << [(index + 1).to_s, filtered[:words][value][:word].downcase]
152
132
  end
153
133
  questions << q
154
134
  end
155
135
  end
156
136
 
157
- return questions
137
+ questions
158
138
  end
159
-
139
+ # rubocop:enable Lint/BooleanSymbol
140
+ # rubocop:enable Metrics/MethodLength
141
+ # rubocop:enable Metrics/AbcSize
142
+ # rubocop:enable Metrics/BlockLength
143
+ # rubocop:enable Metrics/CyclomaticComplexity
144
+ # rubocop:enable Metrics/PerceivedComplexity
160
145
  end