Class: Examen::Exam

Inherits:
Object
  • Object
show all
Defined in:
lib/examen/exam.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Exam

Returns a new instance of Exam.



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

def initialize (args)
    @preguntas = args[:preguntas] 
    @respuescorrectas=args[:respuescorrectas]
end

Instance Attribute Details

#preguntasObject (readonly)

Returns the value of attribute preguntas.



12
13
14
# File 'lib/examen/exam.rb', line 12

def preguntas
  @preguntas
end

#respuescorrectasObject (readonly)

Returns the value of attribute respuescorrectas.



12
13
14
# File 'lib/examen/exam.rb', line 12

def respuescorrectas
  @respuescorrectas
end

Instance Method Details

#compresp(resp) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/examen/exam.rb', line 31

def compresp(resp)
    correctas=0 
    i=0
    n=0
    
    while n < 5 do
        if @respuescorrectas[i] == resp[i]
            correctas+=1
        end
        i+=1 
        n+=1
    end
    if correctas < (i/2)+1
        mensaje = "Ha suspendido el examen: #{correctas}/#{i}"
    else
        if correctas == i
             mensaje = "Su nota es: Sobresaliente 10"
        else
            mensaje = "Ha aprobado el examen: #{correctas}/#{i}"
        end
    end
    mensaje
end

#insertQuestion(question) ⇒ Object



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

def insertQuestion(question)
    nodo=Nodo.new(question)
    nodoInsertado = @preguntas.pushf(nodo)
    nodoInsertado.value
end

#insertQuestion2(question) ⇒ Object



24
25
26
27
28
# File 'lib/examen/exam.rb', line 24

def insertQuestion2(question)
    nodo=Nodo.new(question)
    nodoInsertado = @preguntas.push(nodo)
    nodoInsertado.value
end

#invertirObject



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/examen/exam.rb', line 66

def invertir
       aux = @preguntas.fin
       respuesta = ""
       respuesta += aux.value.to_s
       respuesta += "\n"
       while (aux != @preguntas.inicio) do
           aux = aux.prev
           respuesta += aux.value.to_s
           respuesta += "\n"
       end
       respuesta
end

#invertirfuncional(arr) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/examen/exam.rb', line 79

def invertirfuncional(arr)
    #aux=%W(#{arr})
    #lambda {|a| a.map(&:reverse) }.call(aux.reverse)
   arr2=Array.new
   arr.reverse_each do |z|
   arr2.push(z)
   end
   arr2
end

#invertirlambda(lista) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/examen/exam.rb', line 93

def invertirlambda(lista)
    aux=Array.new
    aux.push(lista)
    invertir = lambda { reverse } #es igual decir lambda ->
    aux=lista.instance_exec(&invertir)
    
    return aux
    
        
end

#respuObject



61
62
63
# File 'lib/examen/exam.rb', line 61

def respu       
    @respuescorrectas
end