Class: Questions::TextBox
- Inherits:
-
Object
- Object
- Questions::TextBox
- Defined in:
- lib/erik-text-box.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(index, question_json) ⇒ TextBox
constructor
A new instance of TextBox.
- #mark(answer) ⇒ Object
- #name ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(index, question_json) ⇒ TextBox
Returns a new instance of TextBox.
5 6 7 8 9 |
# File 'lib/erik-text-box.rb', line 5 def initialize(index, question_json) @index = index @text = question_json['question'] @answer = question_json['answer'] end |
Class Method Details
.schema ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/erik-text-box.rb', line 24 def self.schema { "properties": { "question": { "type": "string" }, "type": { "type": "string", "pattern": "^text-box$" }, "answer": { "type": "string" } }, "required": [ "question", "type", "answer" ], "additionalProperties": false } end |
Instance Method Details
#mark(answer) ⇒ Object
15 16 17 18 |
# File 'lib/erik-text-box.rb', line 15 def mark(answer) correct = answer && (answer.strip == @answer.strip) QuestionFeedback.new(correct, correct ? nil : %(The correct answer was "#{@answer}".)) end |
#name ⇒ Object
11 12 13 |
# File 'lib/erik-text-box.rb', line 11 def name @text end |
#to_html ⇒ Object
20 21 22 |
# File 'lib/erik-text-box.rb', line 20 def to_html %(<input type="text" name="q-#{@index}" />) end |