asker-tool 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -19
  3. data/bin/asker +2 -1
  4. data/lib/asker/ai/ai.rb +10 -3
  5. data/lib/asker/ai/ai_calculate.rb +20 -6
  6. data/lib/asker/ai/code/base_code_ai.rb +104 -0
  7. data/lib/asker/{code/ai → ai/code}/code_ai_factory.rb +11 -1
  8. data/lib/asker/{code/ai → ai/code}/javascript_code_ai.rb +2 -5
  9. data/lib/asker/ai/code/problem_code_ai.rb +176 -0
  10. data/lib/asker/{code/ai → ai/code}/python_code_ai.rb +2 -5
  11. data/lib/asker/{code/ai → ai/code}/ruby_code_ai.rb +14 -7
  12. data/lib/asker/{code/ai → ai/code}/sql_code_ai.rb +2 -5
  13. data/lib/asker/ai/concept_ai.rb +12 -2
  14. data/lib/asker/ai/question.rb +28 -6
  15. data/lib/asker/ai/stages/base_stage.rb +45 -6
  16. data/lib/asker/ai/stages/stage_b.rb +100 -50
  17. data/lib/asker/ai/stages/stage_d.rb +75 -90
  18. data/lib/asker/ai/stages/stage_f.rb +64 -36
  19. data/lib/asker/ai/stages/stage_i.rb +79 -92
  20. data/lib/asker/ai/stages/stage_s.rb +41 -36
  21. data/lib/asker/ai/stages/stage_t.rb +149 -108
  22. data/lib/asker/application.rb +24 -7
  23. data/lib/asker/checker.rb +149 -52
  24. data/lib/asker/cli.rb +37 -32
  25. data/lib/asker/data/code.rb +76 -0
  26. data/lib/asker/data/column.rb +31 -21
  27. data/lib/asker/data/concept.rb +108 -65
  28. data/lib/asker/data/data_field.rb +14 -0
  29. data/lib/asker/data/row.rb +75 -52
  30. data/lib/asker/data/table.rb +91 -42
  31. data/lib/asker/data/template.rb +3 -1
  32. data/lib/asker/data/world.rb +61 -32
  33. data/lib/asker/{exporter/code_screen_exporter.rb → displayer/code_displayer.rb} +13 -6
  34. data/lib/asker/displayer/concept_ai_displayer.erb +10 -0
  35. data/lib/asker/displayer/concept_ai_displayer.rb +133 -0
  36. data/lib/asker/displayer/concept_displayer.rb +34 -0
  37. data/lib/asker/displayer/stats_displayer.rb +22 -0
  38. data/lib/asker/exporter/code_gift_exporter.rb +10 -11
  39. data/lib/asker/exporter/concept_ai_gift_exporter.rb +21 -13
  40. data/lib/asker/exporter/concept_ai_moodle_exporter.rb +44 -0
  41. data/lib/asker/exporter/concept_ai_yaml_exporter.rb +14 -9
  42. data/lib/asker/exporter/concept_doc_exporter.rb +21 -14
  43. data/lib/asker/exporter/data_gift_exporter.rb +29 -0
  44. data/lib/asker/exporter/output_file_exporter.rb +21 -0
  45. data/lib/asker/files/{config.ini → asker.ini} +48 -1
  46. data/lib/asker/files/example-concept.haml +24 -8
  47. data/lib/asker/files/language/du/connectors.yaml +81 -0
  48. data/lib/asker/files/language/du/mistakes.yaml +82 -0
  49. data/lib/asker/files/language/du/templates.yaml +29 -0
  50. data/lib/asker/files/language/en/connectors.yaml +44 -0
  51. data/lib/asker/files/language/en/mistakes.yaml +37 -0
  52. data/lib/asker/files/language/en/templates.yaml +29 -0
  53. data/lib/asker/files/language/es/connectors.yaml +92 -0
  54. data/lib/asker/files/language/es/mistakes.yaml +84 -0
  55. data/lib/asker/files/language/es/templates.yaml +29 -0
  56. data/lib/asker/files/language/fr/connectors.yaml +76 -0
  57. data/lib/asker/files/language/fr/mistakes.yaml +82 -0
  58. data/lib/asker/files/language/fr/templates.yaml +29 -0
  59. data/lib/asker/files/language/javascript/connectors.yaml +11 -0
  60. data/lib/asker/files/language/javascript/mistakes.yaml +30 -0
  61. data/lib/asker/files/language/javascript/templates.yaml +3 -0
  62. data/lib/asker/files/language/math/connectors.yaml +2 -0
  63. data/lib/asker/files/language/math/mistakes.yaml +2 -0
  64. data/lib/asker/files/language/math/templates.yaml +1 -0
  65. data/lib/asker/files/language/python/connectors.yaml +11 -0
  66. data/lib/asker/files/language/python/mistakes.yaml +26 -0
  67. data/lib/asker/files/language/python/templates.yaml +3 -0
  68. data/lib/asker/files/language/ruby/connectors.yaml +11 -0
  69. data/lib/asker/files/language/ruby/mistakes.yaml +33 -0
  70. data/lib/asker/files/language/ruby/templates.yaml +3 -0
  71. data/lib/asker/files/language/sql/connectors.yaml +6 -0
  72. data/lib/asker/files/language/sql/mistakes.yaml +11 -0
  73. data/lib/asker/files/language/sql/templates.yaml +2 -0
  74. data/lib/asker/formatter/concept_string_formatter.rb +13 -9
  75. data/lib/asker/formatter/moodle/matching.erb +38 -0
  76. data/lib/asker/formatter/moodle/multichoice.erb +49 -0
  77. data/lib/asker/formatter/moodle/shortanswer.erb +30 -0
  78. data/lib/asker/formatter/moodle/truefalse.erb +47 -0
  79. data/lib/asker/formatter/question_gift_formatter.rb +30 -20
  80. data/lib/asker/formatter/question_moodle_formatter.rb +27 -0
  81. data/lib/asker/lang/lang.rb +18 -12
  82. data/lib/asker/lang/lang_factory.rb +32 -5
  83. data/lib/asker/lang/text_actions.rb +87 -69
  84. data/lib/asker/loader/code_loader.rb +4 -4
  85. data/lib/asker/loader/content_loader.rb +16 -12
  86. data/lib/asker/loader/directory_loader.rb +3 -3
  87. data/lib/asker/loader/embedded_file.rb +42 -0
  88. data/lib/asker/loader/file_loader.rb +3 -12
  89. data/lib/asker/loader/haml_loader.rb +15 -0
  90. data/lib/asker/loader/image_url_loader.rb +9 -11
  91. data/lib/asker/loader/input_loader.rb +24 -8
  92. data/lib/asker/loader/project_loader.rb +42 -30
  93. data/lib/asker/logger.rb +30 -6
  94. data/lib/asker/project.rb +28 -117
  95. data/lib/asker/skeleton.rb +40 -29
  96. data/lib/asker.rb +68 -79
  97. metadata +57 -74
  98. data/docs/changelog/v2.1.md +0 -99
  99. data/docs/commands.md +0 -12
  100. data/docs/contributions.md +0 -18
  101. data/docs/history.md +0 -40
  102. data/docs/idea.md +0 -44
  103. data/docs/inputs/README.md +0 -39
  104. data/docs/inputs/code.md +0 -69
  105. data/docs/inputs/concepts.md +0 -142
  106. data/docs/inputs/jedi.md +0 -68
  107. data/docs/inputs/tables.md +0 -112
  108. data/docs/inputs/templates.md +0 -87
  109. data/docs/install/README.md +0 -38
  110. data/docs/install/manual.md +0 -26
  111. data/docs/install/scripts.md +0 -38
  112. data/docs/revise/asker-file.md +0 -41
  113. data/docs/revise/buenas-practicas/01-convocatoria.md +0 -30
  114. data/docs/revise/buenas-practicas/02-formulario.md +0 -35
  115. data/docs/revise/buenas-practicas/03-descripcion.md +0 -63
  116. data/docs/revise/buenas-practicas/04-resultados.md +0 -17
  117. data/docs/revise/buenas-practicas/05-reproducir.md +0 -10
  118. data/docs/revise/ejemplos/01/README.md +0 -27
  119. data/docs/revise/ejemplos/02/README.md +0 -31
  120. data/docs/revise/ejemplos/03/README.md +0 -31
  121. data/docs/revise/ejemplos/04/README.md +0 -37
  122. data/docs/revise/ejemplos/05/README.md +0 -25
  123. data/docs/revise/ejemplos/06/README.md +0 -43
  124. data/docs/revise/ejemplos/README.md +0 -11
  125. data/docs/revise/projects.md +0 -74
  126. data/lib/asker/code/ai/base_code_ai.rb +0 -48
  127. data/lib/asker/code/code.rb +0 -53
  128. data/lib/asker/exporter/concept_ai_screen_exporter.rb +0 -115
  129. data/lib/asker/exporter/concept_screen_exporter.rb +0 -25
  130. data/lib/asker/exporter/main.rb +0 -9
@@ -0,0 +1,82 @@
1
+ ---
2
+ :a: 'á,e,o,ha'
3
+ :"a ": 'as '
4
+ :"as ": 'a ,os '
5
+ :á: 'a,é,há'
6
+ :al: 'ar,la'
7
+ :ar: 'al'
8
+ :b: 'v'
9
+ :c: 's,k'
10
+ :ca: 'ka'
11
+ :ce: 'se,que'
12
+ :ci: 'si,qui'
13
+ :co: 'ko'
14
+ :cu: 'ku,qu'
15
+ :e: 'é,a,he'
16
+ :é: 'e,hé'
17
+ :el: 'er'
18
+ :er: 'el'
19
+ :g: 'j'
20
+ :h: ' ,n'
21
+ :ha: 'a'
22
+ :he: 'e'
23
+ :hi: 'i'
24
+ :ho: 'o'
25
+ :hu: 'u'
26
+ :i: 'í,y'
27
+ :í: 'i,y'
28
+ :j: 'g'
29
+ :k: 'q'
30
+ :l: 'r'
31
+ :lla: 'ya'
32
+ :lle: 'ye'
33
+ :lli: 'yi'
34
+ :llo: 'yo'
35
+ :llu: 'yu'
36
+ :n: 'm,ñ'
37
+ :ñ: 'n'
38
+ :m: 'n'
39
+ :mb: 'nb'
40
+ :mp: 'np'
41
+ :o: 'ó,e'
42
+ :"o ": 'os '
43
+ :ó: 'o'
44
+ :ol: 'or'
45
+ :or: 'ol'
46
+ :os : 'o ,as '
47
+ :oha: 'oa'
48
+ :p: 'q,o'
49
+ :que: 'ke'
50
+ :qui: 'ki'
51
+ :s: 'z,a'
52
+ :sa: 'za'
53
+ :se: 'ce,ze'
54
+ :si: 'ci,zi'
55
+ :so: 'zo'
56
+ :su: 'zu'
57
+ :st: 'ts'
58
+ :t: 'f,p'
59
+ :u: 'ú'
60
+ :ú: 'u'
61
+ :ul: 'ur'
62
+ :ur: 'ul'
63
+ :v: 'b,w'
64
+ :w: 'v, gu'
65
+ :wa: 'gua'
66
+ :we: 'gue'
67
+ :wi: 'gui'
68
+ :wo: 'guo'
69
+ :x: 'ks,k,s'
70
+ :y: 'i,v'
71
+ :" y ": ' e '
72
+ :ya: 'lla'
73
+ :ye: 'lle'
74
+ :yi: 'lli'
75
+ :yo: 'llo'
76
+ :yu: 'llu'
77
+ :z: 's'
78
+ :za: 'sa'
79
+ :ze: 'se'
80
+ :zi: 'si'
81
+ :zo: 'so'
82
+ :zu: 'su'
@@ -0,0 +1,29 @@
1
+ ---
2
+ :none: "Aucune réponse n'est correcte"
3
+ :error: 'Erreur'
4
+ :misspelling: 'Erreur ortographique'
5
+ :true: 'Vrai'
6
+ :false: 'Faux'
7
+ :d1: "Définition: <i><%=text1%></i><br/>Choisissez l'option qui correspond le mieux à la définition précédente.<br/>"
8
+ :d2: 'Définition de <b><%=text1%></b>:<br/> <i><%=text2%></i><br/>'
9
+ :d3: 'Définition de <b><%=text1%></b>:<br/> <i><%=text2%></i><br/></br><p>Note: Chaque symbole ? représente une lettre, et * un ou plusieurs mots.</p>'
10
+ :d4: 'Définition de <b><%=text1%></b>:<br/> <i><%=text2%></i><br/><br/>(Mettez chaque mot à la bonne position dans le texte)'
11
+ :b1: 'Par rapport au concept <b><%=text1%></b>, associez chaque "<%=text2%>" avec son,sa "<%=text3%>".<br/>'
12
+ :f1: 'Les éléments suivants sont "<%=text2%>" du concept <b><%=text1%></b>:<ul><li><%=text3%></li></ul>'
13
+ :f2: "Les éléments suivants sont \"<%=text2%>\".<br/>Sélectionnez l'option qui n'appartient pas au concept <b><%=text1%></b>."
14
+ :f3: 'Les éléments suivants sont "<%=text2%>" du concept <b><%=text1%></b>:<br><p><%=text3%></p>(Mettez chaque mot à la bonne position dans le texte)'
15
+ :i1: "<%=text1%><br/>Choisissez l'option qui correspond le mieux à l'image précédente.<br/>"
16
+ :i2: "<%=text1%><br/>L'image précédente correspond à <b><%=text2%></b>."
17
+ :i3: "<%=text1%><br/>Écrivez l'option <%=text2%>, qui correspond le mieux à l'image précédente.<br/>"
18
+ :i4: '<%=text1%><br/>Définition: <i><%=text2%></i><br/><br/>(Mettez chaque mot à la bonne position dans le texte)'
19
+ :s1: "Par rapport au concept <b><%=text1%></b>, mettez dans l'ordre chaque \"<%=text2%>\" afin que le critère soit rempli \"<%=text3%>\".<br/>"
20
+ :t1table: "Concept <b><%=text1%></b><br/><%=text2%>: [*]<br/><%=text3%>: \"<%=text4%>\"<br/>Choisissez l'option correcte.<br/>"
21
+ :t2table: "Concept <b><%=text1%></b><br/><%=text2%>: [*]<br/><%=text3%>: \"<%=text4%>\"<br/>Choisissez l'option correcte.<br/>"
22
+ :t3table: "Concept <b><%=text1%></b><br/><%=text2%>: \"<%=text3%>\"<br/><%=text4%>: [*]<br/>Choisissez l'option correcte.<br/>"
23
+ :t4table: "Concept <b><%=text1%></b><br/><%=text2%>: \"<%=text3%>\"<br/><%=text4%>: [*]<br/>Choisissez l'option correcte.<br/>"
24
+ :t5table: "Concept <b><%=text1%></b><br/>L'association suivante est correcte:<br/><ul><li><%=text2%>: \"<%=text3%>\"</li><li><%=text4%>: \"<%=text5%>\"</li></ul>"
25
+ :t6table: "Concept <b><%=text1%></b><br/>L'association suivante est correcte:<br/><ul><li><%=text2%>: \"<%=text3%>\"</li><li><%=text4%>: \"<%=text5%>\"</li></ul>"
26
+ :t7table: "Concept <b><%=text1%></b><br/>L'association suivante est correcte:<br/><ul><li><%=text2%>: \"<%=text3%>\"</li><li><%=text4%>: \"<%=text5%>\"</li></ul>"
27
+ :t8table: "Concept <b><%=text1%></b><br/>Complétez l'association suivante:<br/><ul><li><%=text2%>: \"<%=text3%>\"</li><li><%=text4%>: [*]</li></ul>Écrire un mot.<br/>"
28
+ :t9table: "Concept <b><%=text1%></b><br/>Complétez l'association suivante:<br/><ul><li><%=text2%>: \"<%=text3%>\"</li><li><%=text4%>: <%=text5%></li></ul>Écrire<%=text6%> mots.<br/>"
29
+ :code1: "<pre><%=text1%></pre><br/><p>Écrire le numéro de ligne où se trouve la première erreur. Écrire 0 s'il n'y a aucune erreur.</p>"
@@ -0,0 +1,11 @@
1
+ ---
2
+ - '[*]'
3
+ - '.'
4
+ - ','
5
+ - ';'
6
+ - '('
7
+ - ')'
8
+ - '{'
9
+ - '}'
10
+ - '['
11
+ - ']'
@@ -0,0 +1,30 @@
1
+ ---
2
+ :'else': 'else:'
3
+ :elif: 'elseif,else if,elsif'
4
+ :if: 'fi'
5
+ :'document.': 'documento.,document .'
6
+ :'write(': 'write.(,print(,(write '
7
+ :alert: 'alerta,aletr,alart'
8
+ :new: 'nev,naw'
9
+ :function: 'funtion,funtcion,def,defun'
10
+ :#!: '#'
11
+ :": "', "
12
+ :': '", '
13
+ :', ': '; ,. '
14
+ :.: ' ,:,;,. '
15
+ :,: ' ,.,;'
16
+ :;: ':, '
17
+ :(: '[,\{,),(('
18
+ :((: '('
19
+ :): '],\},(,))'
20
+ :)): ')'
21
+ :{: '[,(,\}'
22
+ :}: '],),\}'
23
+ :==: '\=,!='
24
+ :=>: '==,\=,<=,>>,->'
25
+ :' = ': ' == '
26
+ :'!=': '==,\='
27
+ :' + ': ' - '
28
+ :' - ': ' + '
29
+ :'-': '_'
30
+ :'_': '-'
@@ -0,0 +1,3 @@
1
+ ---
2
+ :code1: '<pre><%=text1%></pre><br/><p>Escribir el número de línea donde está el primer error. Escribir 0 si no hay ningún error.</p>'
3
+ :code2: '<pre><%=text1%></pre><br/><p>Elegir el número de línea donde está el primer error. Elegir 0 si no hay ningún error.</p>'
@@ -0,0 +1,2 @@
1
+ ---
2
+ - '[*]'
@@ -0,0 +1,2 @@
1
+ ---
2
+ :0: '1'
@@ -0,0 +1,11 @@
1
+ ---
2
+ - '[*]'
3
+ - '.'
4
+ - ','
5
+ - ';'
6
+ - '('
7
+ - ')'
8
+ - '{'
9
+ - '}'
10
+ - '['
11
+ - ']'
@@ -0,0 +1,26 @@
1
+ ---
2
+ :'else:': 'else '
3
+ :elif: 'elseif,else if,elsif'
4
+ :if: 'fi'
5
+ :' print ': ' puts , prints, echo '
6
+ :#!: '#'
7
+ :": "', "
8
+ :': '", '
9
+ :', ': '; ,. '
10
+ :.: ' ,:,;'
11
+ :,: ' ,.,;'
12
+ :;: ':'
13
+ :(: '[,\{,)'
14
+ :((: '('
15
+ :): '],\},('
16
+ :)): ')'
17
+ :{: '[,(,\}'
18
+ :}: '],),\}'
19
+ :==: '\=,!='
20
+ :=>: '==,\=,<=,>>,->'
21
+ :' = ': ' == '
22
+ :'!=': '==,\='
23
+ :' + ': ' - '
24
+ :' - ': ' + '
25
+ :'-': '_'
26
+ :'_': '-'
@@ -0,0 +1,3 @@
1
+ ---
2
+ :code1: '<pre><%=text1%></pre><br/><p>Escribir el número de línea donde está el primer error. Escribir 0 si no hay ningún error.</p>'
3
+ :code2: '<pre><%=text1%></pre><br/><p>Elegir el número de línea donde está el primer error. Elegir 0 si no hay ningún error.</p>'
@@ -0,0 +1,11 @@
1
+ ---
2
+ - '[*]'
3
+ - '.'
4
+ - ','
5
+ - ';'
6
+ - '('
7
+ - ')'
8
+ - '{'
9
+ - '}'
10
+ - '['
11
+ - ']'
@@ -0,0 +1,33 @@
1
+ ---
2
+ :' do ': ' ( , [ '
3
+ :' elsif ': ' elif , else if , elseif '
4
+ :' else ': ' if , els , elseif '
5
+ :end: 'edn,begin,],), '
6
+ :' if ': ' unless , fi , else '
7
+ :' unless ': ' if , unles '
8
+ :' puts ': ' put , prints, echo '
9
+ :system(: 'sistem(,execute('
10
+ :'.each ': 'each ,.split '
11
+ :.split: '.each,.spilt,split'
12
+ :#!: '# '
13
+ :": "', "
14
+ :': '", '
15
+ :', ': '; ,. '
16
+ :|: ' ,('
17
+ :.: ' ,:,;'
18
+ :,: ' ,.,;'
19
+ :;: ':'
20
+ :(: '[,)'
21
+ :((: '('
22
+ :): '],('
23
+ :)): ')'
24
+ :{: 'do,[,('
25
+ :}: 'end,],)'
26
+ :==: '\=,!='
27
+ :=>: '==,\=,<=,>>,->'
28
+ :' = ': ' == '
29
+ :'!=': '==,\='
30
+ :' + ': ' - '
31
+ :' - ': ' + '
32
+ :'-': '_'
33
+ :'_': '-'
@@ -0,0 +1,3 @@
1
+ ---
2
+ :code1: '<pre><%=text1%></pre><br/><p>Escribir el número de línea donde está el primer error. Escribir 0 si no hay ningún error.</p>'
3
+ :code2: '<pre><%=text1%></pre><br/><p>Elegir el número de línea donde está el primer error. Elegir 0 si no hay ningún error.</p>'
@@ -0,0 +1,6 @@
1
+ ---
2
+ - '[*]'
3
+ - ','
4
+ - ';'
5
+ - '('
6
+ - ')'
@@ -0,0 +1,11 @@
1
+ ---
2
+ :ALTER: 'MODIFICAR,ATLER,CREATE,DROP'
3
+ :CREATE: 'CREAR,CRETAE,DROP,ALTER'
4
+ :DROP: 'ELIMINAR,DORP,CREATE,ALTER'
5
+ :INTEGER: 'ENTERO,INTEGUER,VARCHAR'
6
+ :TABLE: 'TABLA,TALBE,INDEX,DATABASE'
7
+ :VARCHAR: 'TEXTO,VARHCAR'
8
+ :;: ':'
9
+ :);: ')'
10
+ :(: '[,{'
11
+ :): '],}'
@@ -0,0 +1,2 @@
1
+ ---
2
+ :code1: '<pre><%=text1%></pre><br/><p>Escribir el número de línea donde está el primer error. Escribir 0 si no hay ningún error.</p>'
@@ -11,14 +11,13 @@ module ConceptStringFormatter
11
11
  # @return String
12
12
  def self.to_s(concept)
13
13
  tt = Terminal::Table.new
14
- rows = get_tt_rows(concept)
15
- rows.each { |row| tt.add_row row }
16
- "#{tt}\n"
14
+ get_tt_rows(concept).each { |row| tt.add_row row }
15
+ tt.to_s
17
16
  end
18
17
 
19
18
  # rubocop:disable Metrics/AbcSize
20
19
  # rubocop:disable Metrics/MethodLength
21
- def self.get_tt_rows(concept)
20
+ private_class_method def self.get_tt_rows(concept)
22
21
  rows = []
23
22
  rows << [Rainbow(concept.id.to_s).bright,
24
23
  Rainbow(concept.name(:screen)).white.bg(:blue).bright +
@@ -31,14 +30,19 @@ module ConceptStringFormatter
31
30
  rows << [Rainbow('Referenced by').blue,
32
31
  concept.referenced_by.join(', ')[0...70].to_s]
33
32
  rows << format_texts(concept)
34
- rows << [Rainbow('.def(images)').blue, concept.images.size.to_s]
35
- rows << format_tables(concept)
33
+ unless concept.images.size.zero?
34
+ counter1 = 0
35
+ concept.images.each { |image| counter1 += 1 if image[:file] == :none }
36
+ counter2 = concept.images.size - counter1
37
+ rows << [Rainbow('.def(images)').blue, "#{counter1} text / #{counter2} file"]
38
+ end
39
+ rows << format_tables(concept) unless concept.tables.count.zero?
36
40
  rows << format_neighbors(concept)
37
41
  end
38
42
  # rubocop:enable Metrics/AbcSize
39
43
  # rubocop:enable Metrics/MethodLength
40
44
 
41
- def self.format_texts(concept)
45
+ private_class_method def self.format_texts(concept)
42
46
  list = []
43
47
  concept.texts.each do |i|
44
48
  if i.size < 60
@@ -50,14 +54,14 @@ module ConceptStringFormatter
50
54
  [Rainbow('.def(text)').blue, list.join("\n")]
51
55
  end
52
56
 
53
- def self.format_tables(concept)
57
+ private_class_method def self.format_tables(concept)
54
58
  return [] if concept.tables.count.zero?
55
59
 
56
60
  list = concept.tables.map(&:to_s)
57
61
  [Rainbow('.tables').color(:blue), list.join("\n")]
58
62
  end
59
63
 
60
- def self.format_neighbors(concept)
64
+ private_class_method def self.format_neighbors(concept)
61
65
  list = concept.neighbors[0..4].map do |i|
62
66
  i[:concept].name(:screen) + '(' + i[:value].to_s[0..4] + ')'
63
67
  end
@@ -0,0 +1,38 @@
1
+ <% unless question.comment.nil? || question.comment.empty? %>
2
+ <!-- question: <%= question.comment %> -->
3
+ <% end %>
4
+ <question type="matching">
5
+ <name>
6
+ <text><%= question.name %></text>
7
+ </name>
8
+ <questiontext format="html">
9
+ <text><![CDATA[<%= question.text %>]]></text>
10
+ <% unless question.encode == :none %>
11
+ <%= question.encode %>
12
+ <% end %>
13
+ </questiontext>
14
+ <generalfeedback format="html">
15
+ <text><![CDATA[<%= question.feedback.to_s %>]]></text>
16
+ </generalfeedback>
17
+ <defaultgrade>1.0000000</defaultgrade>
18
+ <penalty>0.3333333</penalty>
19
+ <hidden>0</hidden>
20
+ <shuffleanswers>true</shuffleanswers>
21
+ <correctfeedback format="html">
22
+ <text></text>
23
+ </correctfeedback>
24
+ <partiallycorrectfeedback format="html">
25
+ <text></text>
26
+ </partiallycorrectfeedback>
27
+ <incorrectfeedback format="html">
28
+ <text></text>
29
+ </incorrectfeedback>
30
+ <% question.matching.each do |i, j| %>
31
+ <subquestion format="html">
32
+ <text><![CDATA[<%= i %>]]></text>
33
+ <answer>
34
+ <text><![CDATA[<%= j %>]]></text>
35
+ </answer>
36
+ </subquestion>
37
+ <% end %>
38
+ </question>
@@ -0,0 +1,49 @@
1
+ <% unless question.comment.nil? || question.comment.empty? %>
2
+ <!-- question: <%= question.comment %> -->
3
+ <% end %>
4
+ <question type="multichoice">
5
+ <name>
6
+ <text><%= question.name %></text>
7
+ </name>
8
+ <questiontext format="html">
9
+ <text><![CDATA[<%= question.text %>]]></text>
10
+ <% unless question.encode == :none %>
11
+ <%= question.encode %>
12
+ <% end %>
13
+ </questiontext>
14
+ <generalfeedback format="html">
15
+ <text><![CDATA[<%= question.feedback.to_s %>]]></text>
16
+ </generalfeedback>
17
+ <defaultgrade>1.0000000</defaultgrade>
18
+ <penalty>0.3333333</penalty>
19
+ <hidden>0</hidden>
20
+ <single>true</single>
21
+ <shuffleanswers>true</shuffleanswers>
22
+ <answernumbering>abc</answernumbering>
23
+ <correctfeedback format="html">
24
+ <text></text>
25
+ </correctfeedback>
26
+ <partiallycorrectfeedback format="html">
27
+ <text></text>
28
+ </partiallycorrectfeedback>
29
+ <incorrectfeedback format="html">
30
+ <text></text>
31
+ </incorrectfeedback>
32
+ <answer fraction="100" format="html">
33
+ <text><%= question.good %></text>
34
+ <feedback format="html">
35
+ <text></text>
36
+ </feedback>
37
+ </answer>
38
+ <%
39
+ question.bads.shuffle! if question.shuffle?
40
+ question.bads.each do |i|
41
+ %>
42
+ <answer fraction="<%= penalty %>" format="html">
43
+ <text><![CDATA[<%= i %>]]></text>
44
+ <feedback format="html">
45
+ <text></text>
46
+ </feedback>
47
+ </answer>
48
+ <% end %>
49
+ </question>
@@ -0,0 +1,30 @@
1
+ <% unless question.comment.nil? || question.comment.empty? %>
2
+ <!-- question: <%= question.comment %> -->
3
+ <% end %>
4
+ <question type="shortanswer">
5
+ <name>
6
+ <text><%= question.name %></text>
7
+ </name>
8
+ <questiontext format="html">
9
+ <text><![CDATA[<%= question.text %>]]></text>
10
+ <% unless question.encode == :none %>
11
+ <%= question.encode %>
12
+ <% end %>
13
+ </questiontext>
14
+ <generalfeedback format="html">
15
+ <text><![CDATA[<%= question.feedback.to_s %>]]></text>
16
+ </generalfeedback>
17
+ <defaultgrade>1.0000000</defaultgrade>
18
+ <penalty>0.3333333</penalty>
19
+ <hidden>0</hidden>
20
+ <usecase>0</usecase>
21
+ <% question.shorts.uniq! %>
22
+ <% question.shorts.each do |i| %>
23
+ <answer fraction="100" format="moodle_auto_format">
24
+ <text><![CDATA[<%= i %>]]></text>
25
+ <feedback format="html">
26
+ <text></text>
27
+ </feedback>
28
+ </answer>
29
+ <% end %>
30
+ </question>
@@ -0,0 +1,47 @@
1
+ <% unless question.comment.nil? || question.comment.empty? %>
2
+ <!-- question: <%= question.comment %> -->
3
+ <% end %>
4
+ <question type="truefalse">
5
+ <name>
6
+ <text><%= question.name %></text>
7
+ </name>
8
+ <questiontext format="html">
9
+ <text><![CDATA[<%= question.text %>]]></text>
10
+ <% unless question.encode == :none %>
11
+ <%= question.encode %>
12
+ <% end %>
13
+ </questiontext>
14
+ <generalfeedback format="html">
15
+ <text><![CDATA[<%= question.feedback.to_s %>]]></text>
16
+ </generalfeedback>
17
+ <defaultgrade>1.0000000</defaultgrade>
18
+ <penalty>1.0000000</penalty>
19
+ <hidden>0</hidden>
20
+ <% if question.good == 'TRUE' %>
21
+ <answer fraction="100" format="moodle_auto_format">
22
+ <text>true</text>
23
+ <feedback format="html">
24
+ <text></text>
25
+ </feedback>
26
+ </answer>
27
+ <answer fraction="0" format="moodle_auto_format">
28
+ <text>false</text>
29
+ <feedback format="html">
30
+ <text></text>
31
+ </feedback>
32
+ </answer>
33
+ <% else %>
34
+ <answer fraction="0" format="moodle_auto_format">
35
+ <text>true</text>
36
+ <feedback format="html">
37
+ <text></text>
38
+ </feedback>
39
+ </answer>
40
+ <answer fraction="100" format="moodle_auto_format">
41
+ <text>false</text>
42
+ <feedback format="html">
43
+ <text></text>
44
+ </feedback>
45
+ </answer>
46
+ <% end %>
47
+ </question>
@@ -1,63 +1,73 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: false
2
2
 
3
3
  # Transform Questions into Gift format
4
4
  module QuestionGiftFormatter
5
+ ##
6
+ # Convert question object into gift formatted string
7
+ # @param question (Question)
8
+ # @return String
5
9
  def self.to_s(question)
6
- @question = question
10
+ s = ''
11
+ return s unless question.encode == :none
12
+
7
13
  # Return question using gift format
8
- cond = @question.comment.nil? && @question.comment.empty?
9
- s = "// #{@question.comment}\n" unless cond
10
- s << "::#{@question.name}::[html]#{sanitize(@question.text)}\n"
14
+ cond = question.comment.nil? || question.comment.empty?
15
+ s = "// #{question.comment}\n" unless cond
16
+ s << "::#{question.name}::[html]#{sanitize(question.text)}\n"
11
17
 
12
- case @question.type
18
+ case question.type
13
19
  when :choice
14
20
  s += "{\n"
15
- a = [" =#{sanitize(@question.good)}\n"]
21
+ a = [" =#{sanitize(question.good)}\n"]
16
22
  penalties = ['', '%-50%', '%-33.33333%', '%-25%', '%-20%']
17
- penalty = penalties[@question.bads.size]
23
+ penalty = penalties[question.bads.size]
18
24
 
19
- @question.bads.each { |i| a << (" ~#{penalty}" + sanitize(i) + "\n") }
20
- a.shuffle! if @question.shuffle?
25
+ question.bads.each { |i| a << (" ~#{penalty}" + sanitize(i) + "\n") }
26
+ a.shuffle! if question.shuffle?
21
27
  a.each do |i|
22
28
  text = i
23
29
  text = i[0, 220] + '...(ERROR: text too long)' if text.size > 255
24
30
  s << text
25
31
  end
26
- s += " #####{sanitize(@question.feedback.to_s)}\n" if @question.feedback
32
+ s += " #####{sanitize(question.feedback.to_s)}\n" if question.feedback
27
33
  s += "}\n\n"
28
34
  when :boolean
29
- s << "{#{@question.good}#####{sanitize(@question.feedback.to_s)}}\n\n"
35
+ s << "{#{question.good}#####{sanitize(question.feedback.to_s)}}\n\n"
30
36
  when :match
31
37
  s << "{\n"
32
38
  a = []
33
- @question.matching.each do |i, j|
39
+ question.matching.each do |i, j|
34
40
  i = i[0, 220] + '...(ERROR: text too long)' if i.size > 255
35
41
  j = j[0, 220] + '...(ERROR: text too long)' if j.size > 255
36
42
  a << " =#{sanitize(i)} -> #{sanitize(j)}\n"
37
43
  end
38
- a.shuffle! if @question.shuffle?
44
+ a.shuffle! if question.shuffle?
39
45
  a.each { |i| s << i }
40
46
  s << "}\n\n"
41
47
  when :short
42
48
  s << "{\n"
43
- @question.shorts.uniq!
44
- @question.shorts.each do |i|
49
+ question.shorts.uniq!
50
+ question.shorts.each do |i|
45
51
  text = i
46
52
  text = i[0, 220] + '...(ERROR: too long)' if text.size > 255
47
53
  s << " =%100%#{text}#\n"
48
54
  end
49
- s << " #####{sanitize(@question.feedback.to_s)}\n" if @question.feedback
55
+ s << " #####{sanitize(question.feedback.to_s)}\n" if question.feedback
50
56
  s << "}\n\n"
51
57
  end
52
58
  s
53
59
  end
54
60
 
61
+ ##
62
+ # Sanitize gift text
63
+ # @param input (String)
64
+ # @return String
55
65
  def self.sanitize(input = '')
56
66
  output = input.dup
57
- output.gsub!("#", "\\#")
67
+ output.gsub!('#', '\#')
58
68
  output.gsub!("\n", " ")
59
- #output.gsub!(":", "\\:")
60
- output.gsub!("=", "\\=")
69
+ output.gsub!(':', '\:')
70
+ output.gsub!('=', '\=')
61
71
  output.gsub!("\{", "\\{")
62
72
  output.gsub!("\}", "\\}")
63
73
  output
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'erb'
4
+
5
+ # Transform Questions into Gift format
6
+ module QuestionMoodleFormatter
7
+ ##
8
+ # Convert question object into gift formatted string
9
+ # @param question (Question)
10
+ # @return String
11
+ def self.to_s(question)
12
+ case question.type
13
+ when :choice
14
+ penalties = ['', '-50', '-33.33333', '-25', '-20']
15
+ penalty = penalties[question.bads.size]
16
+ template = File.read(File.join(File.dirname(__FILE__), 'moodle', 'multichoice.erb'))
17
+ when :boolean
18
+ template = File.read(File.join(File.dirname(__FILE__), 'moodle', 'truefalse.erb'))
19
+ when :match
20
+ template = File.read(File.join(File.dirname(__FILE__), 'moodle', 'matching.erb'))
21
+ when :short
22
+ template = File.read(File.join(File.dirname(__FILE__), 'moodle', 'shortanswer.erb'))
23
+ end
24
+ renderer = ERB.new(template)
25
+ renderer.result(binding)
26
+ end
27
+ end