quizzer 0.1.5 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quizzer.rb +71 -24
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a088691ad858eba9fd93169577cb109be6036a24
|
4
|
+
data.tar.gz: 2a46421b0c08ea4c992a7679381221e4e2223978
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c18ca0a72615168a9711a3a4570595bc65fc4471a23117a9a8580ffcc5735833ee5bdcb5c3009483d70d9648cc136954b27f011635c995f8f61f34e4d13a6a9
|
7
|
+
data.tar.gz: 61fe27299306b201e5468a1a6e072cd38e26041ce108dee0992c44c43b125589e830db124cb68adc8bbb6f46e31941ec3b60cfd5294860dba10e4011c9437e6a
|
data/lib/quizzer.rb
CHANGED
@@ -1,31 +1,73 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'open-uri'
|
2
3
|
|
3
|
-
class
|
4
|
-
attr_accessor :
|
4
|
+
class Quizzer
|
5
|
+
attr_accessor :quizz, :assessment, :scores
|
6
|
+
|
7
|
+
def initialize(quizz, assessment)
|
8
|
+
raise "Obligatory quizz and assessment input" unless quizz || assessment
|
9
|
+
|
10
|
+
@quizz = Quizz.new(JSON.parse(Quizzer.get_file(quizz)))
|
11
|
+
@assessment = Assessment.new(JSON.parse(Quizzer.get_file(assessment)))
|
12
|
+
@scores = Scores.new(@quizz, @assessment)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.manifest(file)
|
16
|
+
out = Array.new
|
17
|
+
m = JSON.parse(get_file(file))
|
18
|
+
m["tests"].each do |t|
|
19
|
+
out.push self.test(t["quizz"], t["assessment"], t["scores"])
|
20
|
+
end
|
21
|
+
out
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.test(quizz, assessment, scores)
|
25
|
+
q = Quizzer.new(quizz, assessment)
|
26
|
+
s_test = JSON.parse get_file(scores)
|
27
|
+
if q.scores.test(s_test)
|
28
|
+
return [q, true]
|
29
|
+
else
|
30
|
+
return [q, false]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_scores(output = nil)
|
35
|
+
if output
|
36
|
+
File.open(output,"w") do |f|
|
37
|
+
f.write(@scores.serialize)
|
38
|
+
end
|
39
|
+
true
|
40
|
+
else
|
41
|
+
@scores.serialize
|
42
|
+
end
|
43
|
+
end
|
5
44
|
|
6
|
-
def
|
7
|
-
|
45
|
+
def self.get_file(path)
|
46
|
+
/^http:\/\//.match(path) ? open(path).read : IO.read(path)
|
8
47
|
end
|
9
48
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
49
|
+
end
|
50
|
+
|
51
|
+
class Quizz
|
52
|
+
attr_accessor :questions
|
53
|
+
|
54
|
+
def initialize(quizz)
|
55
|
+
@questions = Hash.new
|
56
|
+
quizz["questions"].each do |q|
|
14
57
|
case q["type"]
|
15
58
|
when 'truefalse' then
|
16
|
-
questions[q["id"]] = TrueFalse.new(q["type"], q["id"], q["questionText"], q["correct"],
|
59
|
+
@questions[q["id"]] = TrueFalse.new(q["type"], q["id"], q["questionText"], q["correct"],
|
17
60
|
{ value_ok: q["valueOK"],
|
18
61
|
value_failed: q["valueFailed"],
|
19
62
|
feedback: q["feedback"] })
|
20
63
|
when 'multichoice' then
|
21
64
|
alt = Hash.new
|
22
65
|
q["alternatives"].each { |a| alt[a["code"]] = Alternative.new(a["text"], a["code"], a["value"]) }
|
23
|
-
questions[q["id"]] = Multichoice.new(q["type"], q["id"], q["questionText"], alt)
|
66
|
+
@questions[q["id"]] = Multichoice.new(q["type"], q["id"], q["questionText"], alt)
|
24
67
|
else
|
25
|
-
raise "
|
68
|
+
raise "Unknown type of question"
|
26
69
|
end
|
27
70
|
end
|
28
|
-
return Quizz.new(questions)
|
29
71
|
end
|
30
72
|
end
|
31
73
|
|
@@ -68,19 +110,13 @@ end
|
|
68
110
|
|
69
111
|
class Assessment
|
70
112
|
attr_accessor :items
|
71
|
-
def initialize(
|
72
|
-
@items =
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.parse(assessment)
|
76
|
-
assessment = JSON.parse(IO.read(assessment))
|
77
|
-
items = Hash.new
|
113
|
+
def initialize(assessment)
|
114
|
+
@items = Hash.new
|
78
115
|
assessment["items"].each do |i|
|
79
116
|
answers = Hash.new
|
80
117
|
i["answers"].each { |a| answers[a["question"]] = Answer.new(a["question"], a["value"]) }
|
81
|
-
items[i["studentId"]] = Item.new(i["studentId"], answers)
|
118
|
+
@items[i["studentId"]] = Item.new(i["studentId"], answers)
|
82
119
|
end
|
83
|
-
return Assessment.new(items)
|
84
120
|
end
|
85
121
|
end
|
86
122
|
|
@@ -124,14 +160,21 @@ class Scores
|
|
124
160
|
end
|
125
161
|
end
|
126
162
|
|
163
|
+
def test(another)
|
164
|
+
s_test = Hash.new
|
165
|
+
another["scores"].each do |s|
|
166
|
+
s_test[s["studentId"]] = Score.new(s["studentId"], s["value"])
|
167
|
+
end
|
168
|
+
|
169
|
+
@scores == s_test
|
170
|
+
end
|
171
|
+
|
127
172
|
def serialize()
|
128
173
|
output = { "scores" => Array.new }
|
129
174
|
@scores.each do |s_id, s|
|
130
175
|
output["scores"].push({ "studentId" => s_id, "value" => s.value })
|
131
176
|
end
|
132
|
-
|
133
|
-
f.write(JSON.pretty_generate(output))
|
134
|
-
end
|
177
|
+
JSON.pretty_generate(output)
|
135
178
|
end
|
136
179
|
end
|
137
180
|
|
@@ -141,5 +184,9 @@ class Score
|
|
141
184
|
@student_id = student_id
|
142
185
|
@value = value
|
143
186
|
end
|
187
|
+
|
188
|
+
def == (score)
|
189
|
+
@student_id == score.student_id && @value == score.value
|
190
|
+
end
|
144
191
|
end
|
145
192
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quizzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Cepillo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
41
|
+
description:
|
42
42
|
email:
|
43
43
|
- adrian.cepillo@gmail.com
|
44
44
|
executables: []
|
@@ -46,7 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- lib/quizzer.rb
|
49
|
-
homepage: http://
|
49
|
+
homepage: http://bitbucket.org/adrian_cm/quizzer-ruby
|
50
50
|
licenses:
|
51
51
|
- MIT
|
52
52
|
metadata: {}
|
@@ -69,5 +69,6 @@ rubyforge_project:
|
|
69
69
|
rubygems_version: 2.2.2
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
|
-
summary:
|
72
|
+
summary: Quizzer package evaluate exams and answers from students and generate scores
|
73
|
+
for everyone.
|
73
74
|
test_files: []
|