Class: Pregunta

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/exam/preguntaMadre.rb

Overview

Clase base de las preguntas. No contiene respuestas.

Direct Known Subclasses

PreguntaS, PreguntaVF

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pregunta, dificultad) ⇒ Pregunta

Método constructor



11
12
13
14
15
# File 'lib/exam/preguntaMadre.rb', line 11

def initialize(pregunta, dificultad)
  @pr = pregunta
       @df = dificultad
       @correcta = nil #debe modificarse; int que refiere a pos en Array de pr. 
end

Instance Attribute Details

#correctaObject

Returns the value of attribute correcta.



6
7
8
# File 'lib/exam/preguntaMadre.rb', line 6

def correcta
  @correcta
end

#dfObject (readonly)

Returns the value of attribute df.



5
6
7
# File 'lib/exam/preguntaMadre.rb', line 5

def df
  @df
end

#prObject (readonly)

Returns the value of attribute pr.



5
6
7
# File 'lib/exam/preguntaMadre.rb', line 5

def pr
  @pr
end

Instance Method Details

#<=>(other) ⇒ Object

Método de comparación (se fija en la dificultad)



18
19
20
# File 'lib/exam/preguntaMadre.rb', line 18

def <=> (other)
    @df <=> other.df
end

#==(other) ⇒ Object

Evitamos que se consideren iguales dos preguntas cualquiera sólo porque tengan la misma dificultad. Esto es una sobrecarga del método de comparación.



25
26
27
# File 'lib/exam/preguntaMadre.rb', line 25

def == (other)
    @pr == other.pr && @df == other.df
end

#resp_correcta?(resp) ⇒ Boolean

Método que contrasta la respuesta entregada (por parámetro) con el atributo que señala la respuesta correcta.

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/exam/preguntaMadre.rb', line 31

def resp_correcta?(resp)
  if resp.to_i != 0
#sera numero, lo pasamos a int.
    resp = resp.to_i
  else
#sera String, admitimos mayus y minus.
    resp.upcase!
  end
  
  if resp == @correcta
    true
  else
    false
  end
end