Class: Quiz

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

Overview

Clase gestora de un DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, &block) ⇒ Quiz

Crea una Instancia de la clase Quiz, a partir de un título y un bloque



7
8
9
10
11
12
13
# File 'lib/examen/quiz.rb', line 7

def initialize(title, &block)
  @title = title
  @exam = Exam.new(Pregunta.new(:text => "dummy", :right => "dummy", :distractors => ["dummy"]))
  @exam.list.pop
  @count = 0 
  instance_eval &block
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



5
6
7
# File 'lib/examen/quiz.rb', line 5

def count
  @count
end

#examObject

Returns the value of attribute exam.



5
6
7
# File 'lib/examen/quiz.rb', line 5

def exam
  @exam
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/examen/quiz.rb', line 5

def title
  @title
end

Instance Method Details

#question(*args) ⇒ Object

Actualiza el examen actual, con una nueva pregunta



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

def question(*args)
  distract = Array.new
  args[1].keys.each { |x| distract << args[1][x] if x.class.equal? Array }
  exam << Pregunta.new(:text => args[0], :right => args[1][:right], :distractors => distract)
  exam
end

#rightObject

Devuelve el Simbolo :right



15
16
17
# File 'lib/examen/quiz.rb', line 15

def right
  :right
end

#to_sObject

Definicion del Metodo to_s, para la Clase Quiz



31
32
33
# File 'lib/examen/quiz.rb', line 31

def to_s
  "\s\s#{@title}\n#{'#' * (@title.size + 4)}\n\n#{@exam}"
end

#wrongObject

Devuelve un Array con el Simbolo :wrong y un indice



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

def wrong
  @count += 1
  [:wrong, @count]
end