Class: Quiz
- Inherits:
-
Object
- Object
- Quiz
- Defined in:
- lib/quiz/quiz.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(title, &block) ⇒ Quiz
constructor
A new instance of Quiz.
- #question(text, answers = {}) ⇒ Object
- #right ⇒ Object
- #to_exam ⇒ Object
- #wrong ⇒ Object
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
#list ⇒ Object
Returns the value of attribute list.
11 12 13 |
# File 'lib/quiz/quiz.rb', line 11 def list @list end |
#title ⇒ Object
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 |
#right ⇒ Object
32 33 34 |
# File 'lib/quiz/quiz.rb', line 32 def right :right end |
#to_exam ⇒ Object
40 41 42 |
# File 'lib/quiz/quiz.rb', line 40 def to_exam Examen.new(@list) end |
#wrong ⇒ Object
36 37 38 39 |
# File 'lib/quiz/quiz.rb', line 36 def wrong @i = @i + 1 ("distractor"+@i.to_s).intern end |