Class: Exam::Test

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

Overview

create a Test

Direct Known Subclasses

ToF

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pregunta, correcta, respuestas, nivel = nil) ⇒ Test

Returns a new instance of Test.



17
18
19
20
21
22
# File 'lib/exam/test.rb', line 17

def initialize(pregunta, correcta, respuestas, nivel=nil)
  @pregunta = pregunta
  @correcta = correcta
  @respuestas = respuestas.shuffle
  @nivel = nivel
end

Instance Attribute Details

#correctaObject

Returns the value of attribute correcta.



7
8
9
# File 'lib/exam/test.rb', line 7

def correcta
  @correcta
end

#nivelObject

Returns the value of attribute nivel.



7
8
9
# File 'lib/exam/test.rb', line 7

def nivel
  @nivel
end

#preguntaObject

Returns the value of attribute pregunta.



7
8
9
# File 'lib/exam/test.rb', line 7

def pregunta
  @pregunta
end

#respuestasObject

Returns the value of attribute respuestas.



7
8
9
# File 'lib/exam/test.rb', line 7

def respuestas
  @respuestas
end

Instance Method Details

#<=>(a) ⇒ Object



9
10
11
# File 'lib/exam/test.rb', line 9

def <=> (a)
  @nivel <=> a.nivel
end

#==(a) ⇒ Object



13
14
15
# File 'lib/exam/test.rb', line 13

def == (a)
  @pregunta==a.pregunta && @correcta==a.correcta && @respuestas.should =~ a.respuestas
end

#check_ans(c) ⇒ Object



24
25
26
# File 'lib/exam/test.rb', line 24

def check_ans(c)
  return (c == @correcta)
end

#to_sObject



28
29
30
31
32
33
34
# File 'lib/exam/test.rb', line 28

def to_s
  texto = "Pregunta: #{@pregunta} \n"
  for i in 0..@respuestas.size-1
    texto = texto + "\t #{i+1}) #{@respuestas[i]} \n"
  end
  return texto
end