Class: Questions::MultipleSelect
- Inherits:
-
Object
- Object
- Questions::MultipleSelect
- Defined in:
- lib/erik-multiple-select.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(index, question_json) ⇒ MultipleSelect
constructor
A new instance of MultipleSelect.
- #mark(answer) ⇒ Object
- #name ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(index, question_json) ⇒ MultipleSelect
Returns a new instance of MultipleSelect.
5 6 7 8 9 10 |
# File 'lib/erik-multiple-select.rb', line 5 def initialize(index, question_json) @index = index @text = question_json['question'] = question_json['options'] @answer = question_json['answer'] end |
Class Method Details
.schema ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/erik-multiple-select.rb', line 31 def self.schema { "properties": { "question": { "type": "string" }, "type": { "type": "string", "pattern": "^multiple-select$" }, "options": { "type": "array", "items": { "type": "string" } }, "answer": { "type": "array", "items": { "type": "integer" } } }, "required": [ "question", "type", "options", "answer" ], "additionalProperties": false } end |
Instance Method Details
#mark(answer) ⇒ Object
16 17 18 19 |
# File 'lib/erik-multiple-select.rb', line 16 def mark(answer) correct = answer == @answer.collect { |a| a.to_s } QuestionFeedback.new(correct, correct ? nil : feedback_string) end |
#name ⇒ Object
12 13 14 |
# File 'lib/erik-multiple-select.rb', line 12 def name @text end |
#to_html ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/erik-multiple-select.rb', line 21 def to_html .collect.with_index do |option, index| id = "q-#{@index}-#{index}" %(<div> <input id="#{id}" type="checkbox" name="q-#{@index}[]" value="#{index}" /> <label for="#{id}">#{option}</label> </div>) end.join("\n") end |