Class: Questions::TextBox

Inherits:
Object
  • Object
show all
Defined in:
lib/erik-text-box.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.schemaObject



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

#nameObject



11
12
13
# File 'lib/erik-text-box.rb', line 11

def name
  @text
end

#to_htmlObject



20
21
22
# File 'lib/erik-text-box.rb', line 20

def to_html
  %(<input type="text" name="q-#{@index}" />)
end