Class: Question
Overview
Clase para la gestion de preguntas de multiples opciones.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#difficulty ⇒ Object
Returns the value of attribute difficulty.
-
#qt ⇒ Object
Returns the value of attribute qt.
-
#r1 ⇒ Object
Returns the value of attribute r1.
-
#wrong ⇒ Object
Returns the value of attribute wrong.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(args) ⇒ Question
constructor
Inicializacion de una nueva instancia de una nueva pregunta a partir de un texto.
-
#to_s ⇒ Object
Metodo to_s.
Constructor Details
#initialize(args) ⇒ Question
Inicializacion de una nueva instancia de una nueva pregunta a partir de un texto.
20 21 22 23 24 25 26 27 28 |
# File 'lib/Exam/question.rb', line 20 def initialize (args) @qt = args[:qt] raise ArgumentError, "Se esperaba una pregunta" unless args.key?(:qt) @r1 = args[:r1] raise ArgumentError, "Se esperaba la respuesta correcta" unless args.key?(:r1) @wrong = args[:wrong] raise ArgumentError, "Se esperaba un array con las respuestas incorrectas" unless args.key?(:wrong) args.has_key?(:difficulty)? (@difficulty = args[:difficulty]) : (@difficulty = 1) end |
Instance Attribute Details
#difficulty ⇒ Object
Returns the value of attribute difficulty.
5 6 7 |
# File 'lib/Exam/question.rb', line 5 def difficulty @difficulty end |
#qt ⇒ Object
Returns the value of attribute qt.
5 6 7 |
# File 'lib/Exam/question.rb', line 5 def qt @qt end |
#r1 ⇒ Object
Returns the value of attribute r1.
5 6 7 |
# File 'lib/Exam/question.rb', line 5 def r1 @r1 end |
#wrong ⇒ Object
Returns the value of attribute wrong.
5 6 7 |
# File 'lib/Exam/question.rb', line 5 def wrong @wrong end |
Instance Method Details
#<=>(other) ⇒ Object
10 11 12 |
# File 'lib/Exam/question.rb', line 10 def <=>(other) @difficulty <=> other.difficulty end |
#==(other) ⇒ Object
14 15 16 |
# File 'lib/Exam/question.rb', line 14 def ==(other) @qt.eql?other.qt end |
#to_s ⇒ Object
Metodo to_s.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/Exam/question.rb', line 32 def to_s s = "#{@qt}\n" opt = [@r1] + @wrong opt = opt.shuffle i = 1 opt.each do |o| s += "#{i}- #{o}\n" i += 1 end s end |