class Questions::SingleSelect
Public Class Methods
new(index, question_json)
click to toggle source
# File lib/erik-single-select.rb, line 5 def initialize(index, question_json) @index = index @text = question_json['question'] @options = question_json['options'] @answer = question_json['answer'] end
schema()
click to toggle source
# File lib/erik-single-select.rb, line 32 def self.schema { "properties": { "question": { "type": "string" }, "type": { "type": "string", "pattern": "^single-select$" }, "options": { "type": "array", "items": { "type": "string" } }, "answer": { "type": "integer", } }, "required": [ "question", "type", "options", "answer" ], "additionalProperties": false } end
Public Instance Methods
mark(answer)
click to toggle source
# File lib/erik-single-select.rb, line 16 def mark(answer) correct = answer == @answer.to_s QuestionFeedback.new(correct, correct ? nil : %(The correct answer was "#{@options[@answer]}".)) end
name()
click to toggle source
# File lib/erik-single-select.rb, line 12 def name @text end
to_html()
click to toggle source
# File lib/erik-single-select.rb, line 21 def to_html options_html = @options.collect.with_index do |option, index| id = "q-#{@index}-#{index}" %(<div> <input id="#{id}" type="radio" name="q-#{@index}" value="#{index}" /> <label for="#{id}">#{option}</label> </div>) end options_html.join("\n") end