Skip to content

Commit

Permalink
Añadiendo codigo para la clase Quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
alu0100600582 committed Dec 10, 2014
1 parent 070db19 commit e6a20b1
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions lib/Examenes/quiz.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-

require 'rubygems'
require 'bundler/setup'
require 'rspec'


module Examenes

class ExamGUI
attr_accessor :exam, :name

def initialize(name = "Sin Nombre", &block)
@exam = ExamenCompleto.new(List.new)
@name = name

instance_eval &block
end

def question(text, options = {})
distractors = []
distractors << options[:wrong] while options[:wrong]

if(options[:right] == 'FALSE' || options[:right] == 'TRUE')
add(:type => 0, :text => text, :right => options[:right])
elsif
add(:type => 1, :text => text, :right => options[:right] , :distractor => distractors )
end
end

def add(args) #Añade una pregunta al examen
if args[:type] == 1 #La pregunta es SimpleChoice
q = PreguntaSimple.new(
:text => args[:text],
:right => args[:right],
:distractor => args[:distractor])
elsif args[:type] == 0 #La pregunta es TrueFalse
q = VerdaderoFalso.new(
:text => args[:text],
:right => args[:right])
end

(@exam.list).push(:elm => [q])
end

def check(resp)
resul = []
i=0
(@exam.order).each do |quest|
resul << (resp[i] == quest.right)
i += 1
end
resul
end

def show
@name + @exam.show
end

def show_i
@name + @exam.show_i
end

def right
:right
end

def wrong
:wrong
end
end
end

0 comments on commit e6a20b1

Please sign in to comment.