Class: QuizDSL
- Inherits:
-
InterfazQuiz
- Object
- Quiz
- InterfazQuiz
- QuizDSL
- Defined in:
- lib/quiz_dsl.rb
Overview
quiz_dsl.rb
- Autor
-
Dailos Sabina Rodriguez
- Autor
-
Raul Perez Hernandez
Clase QuizDSL
Definicion de la clase Quiz que permite representar un examen por pantalla mediante los siguientes metodos y tambien comprobar el resultado del examen, para ello hemos definido la clase como DSL
-
metodo initialize
-
metodo question
-
metodo right
-
metodo wrong
Instance Attribute Summary
Attributes inherited from Quiz
Instance Method Summary collapse
-
#initialize(name = "", &block) ⇒ QuizDSL
constructor
Metodo para inicializar la clase.
-
#question(title, answers = {}) ⇒ Object
Metodo para cargar una pregunta haciendo uso de DSL.
-
#right ⇒ Object
Metodo para cargar la respuesta correcta.
-
#wrong ⇒ Object
Metodo para cargar la/s respuesta/s errĂ³nea/s.
Methods inherited from InterfazQuiz
Methods inherited from Quiz
#check, #invertir, #invertir_manual, #to_s
Constructor Details
#initialize(name = "", &block) ⇒ QuizDSL
Metodo para inicializar la clase
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/quiz_dsl.rb', line 22 def initialize(name = "", &block) @aciertos = 0 @name = name @questions = List.new @wr = 0 if block_given? if block.arity == 1 yield else instance_eval &block end end end |
Instance Method Details
#question(title, answers = {}) ⇒ Object
Metodo para cargar una pregunta haciendo uso de DSL
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/quiz_dsl.rb', line 38 def question(title, answers = {}) resp = [] a = 0 num_c = 0 correcta = answers[:right] if answers[:right] answers.map do |key,r| resp << r num_c = a if r == correcta a += 1 end @questions.ins_final(Exam::Pregunta.new(title, resp, num_c, 0)) end |
#right ⇒ Object
Metodo para cargar la respuesta correcta
52 53 54 |
# File 'lib/quiz_dsl.rb', line 52 def right :right end |
#wrong ⇒ Object
Metodo para cargar la/s respuesta/s errĂ³nea/s
57 58 59 60 |
# File 'lib/quiz_dsl.rb', line 57 def wrong @wr += 1 ("wr"+@wr.to_s).intern end |