class QandA::Questionnaire

Constants

TYPE_REGISTER

Attributes

questions[R]

Public Class Methods

new() click to toggle source
# File lib/questionnaire.rb, line 12
def initialize
  @questions = {}
end

Public Instance Methods

add_question(key, type, *args) click to toggle source
# File lib/questionnaire.rb, line 16
def add_question(key, type, *args)
  type = type.to_sym
  unless TYPE_REGISTER.has_key?(type)
    raise NoSuchQuestionTypeError.new("No such question type '#{type}'")
  end
  @questions[key] = TYPE_REGISTER[type].new(*args)
end
answers() click to toggle source
# File lib/questionnaire.rb, line 31
def answers
  Hash[@questions.map { |key, q| [key, q.answer] }]
end
run() click to toggle source
# File lib/questionnaire.rb, line 25
def run
  @questions.each do |key, q|
    q.ask
  end
end