Class: Quiz

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, &block) ⇒ Quiz

Returns a new instance of Quiz.



12
13
14
15
16
17
18
19
# File 'lib/quiz/quiz.rb', line 12

def initialize (title, &block)
  
  @list = Lista.new()
  @i = 0   
  @title = title   
  @distractor = []
  instance_eval &block
end

Instance Attribute Details

#listObject

Returns the value of attribute list.



11
12
13
# File 'lib/quiz/quiz.rb', line 11

def list
  @list
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/quiz/quiz.rb', line 11

def title
  @title
end

Instance Method Details

#question(text, answers = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/quiz/quiz.rb', line 21

def question(text,answers={})   
  @text = text
  @right = answers[:right] if answers[:right]
  answers.map do |key,value|
    @distractor << value if key != :right
  end
  @list.add(SimpleChoice.new(:text => @text,:right => @right,:distractor => @distractor,:dif => '1'))
  @distractor = []

end

#rightObject



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

def right
  :right
end

#to_examObject



40
41
42
# File 'lib/quiz/quiz.rb', line 40

def to_exam
  Examen.new(@list)
end

#wrongObject



36
37
38
39
# File 'lib/quiz/quiz.rb', line 36

def wrong
  @i = @i + 1  
  ("distractor"+@i.to_s).intern  
end