erik-single-select 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/erik-single-select.rb +62 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c000eaab00e986651e5c0a8ab6f5b9ed195a065
|
4
|
+
data.tar.gz: b3d374f71947c86937f4f8414121c5f7683028af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfddd34432db3ac5f64567b9371f6ae4ce46b0c1b7dd725948a88880b4f519e491319d59a8cad09820d3179bda14705eb4e83157a13e51fa9a1e9358a9099f75
|
7
|
+
data.tar.gz: 94f839b4693fe6a2fa30cd85601ce74f3bf2b9e368e1713397e4450fae76edf91ccf8469c13fac29977935df611649715a02b6ba0d18b2673a6de922052b80cc
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'erik-question-feedback'
|
2
|
+
|
3
|
+
module Questions
|
4
|
+
class SingleSelect
|
5
|
+
def initialize(index, question_json)
|
6
|
+
@index = index
|
7
|
+
@text = question_json['question']
|
8
|
+
@options = question_json['options']
|
9
|
+
@answer = question_json['answer']
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
@text
|
14
|
+
end
|
15
|
+
|
16
|
+
def mark(answer)
|
17
|
+
correct = answer == @answer.to_s
|
18
|
+
QuestionFeedback.new(correct, correct ? nil : %(The correct answer was "#{@options[@answer]}".))
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_html
|
22
|
+
options_html = @options.collect.with_index do |option, index|
|
23
|
+
id = "q-#{@index}-#{index}"
|
24
|
+
%(<div>
|
25
|
+
<input id="#{id}" type="radio" name="q-#{@index}" value="#{index}" />
|
26
|
+
<label for="#{id}">#{option}</label>
|
27
|
+
</div>)
|
28
|
+
end
|
29
|
+
options_html.join("\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.schema
|
33
|
+
{
|
34
|
+
"properties": {
|
35
|
+
"question": {
|
36
|
+
"type": "string"
|
37
|
+
},
|
38
|
+
"type": {
|
39
|
+
"type": "string",
|
40
|
+
"pattern": "^single-select$"
|
41
|
+
},
|
42
|
+
"options": {
|
43
|
+
"type": "array",
|
44
|
+
"items": {
|
45
|
+
"type": "string"
|
46
|
+
}
|
47
|
+
},
|
48
|
+
"answer": {
|
49
|
+
"type": "integer",
|
50
|
+
}
|
51
|
+
},
|
52
|
+
"required": [
|
53
|
+
"question",
|
54
|
+
"type",
|
55
|
+
"options",
|
56
|
+
"answer"
|
57
|
+
],
|
58
|
+
"additionalProperties": false
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erik-single-select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Team Eriksen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: erik-question-feedback
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
description: A single selection question type.
|
28
|
+
email: eriksen@example.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/erik-single-select.rb
|
34
|
+
homepage: http://dams.flippd.it/
|
35
|
+
licenses:
|
36
|
+
- BSD
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.2.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A single selection question type.
|
58
|
+
test_files: []
|