barker 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.simplecov +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +50 -0
- data/LICENSE +22 -0
- data/README.md +204 -0
- data/Rakefile +12 -0
- data/barker.gemspec +29 -0
- data/ci/run +20 -0
- data/lib/barker/answer.rb +11 -0
- data/lib/barker/api/base.rb +145 -0
- data/lib/barker/api/response/base.rb +25 -0
- data/lib/barker/api/response/candidate.rb +38 -0
- data/lib/barker/api/response/candidate_answer.rb +23 -0
- data/lib/barker/api/response/candidate_joker.rb +21 -0
- data/lib/barker/api/response/candidate_question.rb +51 -0
- data/lib/barker/api/response/error.rb +17 -0
- data/lib/barker/api/response/game_show.rb +43 -0
- data/lib/barker/api/response/round.rb +21 -0
- data/lib/barker/api/response.rb +15 -0
- data/lib/barker/api.rb +7 -0
- data/lib/barker/candidate.rb +52 -0
- data/lib/barker/candidate_answer.rb +42 -0
- data/lib/barker/candidate_joker.rb +30 -0
- data/lib/barker/candidate_question.rb +116 -0
- data/lib/barker/candidate_round.rb +32 -0
- data/lib/barker/entity.rb +15 -0
- data/lib/barker/game_show.rb +176 -0
- data/lib/barker/guideline/base.rb +33 -0
- data/lib/barker/guideline/llmcquiz/questions.yaml +300 -0
- data/lib/barker/guideline/llmcquiz.rb +28 -0
- data/lib/barker/guideline/mock.rb +17 -0
- data/lib/barker/guideline.rb +8 -0
- data/lib/barker/import/yaml.rb +22 -0
- data/lib/barker/import.rb +6 -0
- data/lib/barker/joker.rb +28 -0
- data/lib/barker/question.rb +12 -0
- data/lib/barker/quiz.rb +19 -0
- data/lib/barker/repo/memory/game_show.rb +38 -0
- data/lib/barker/repo/memory.rb +8 -0
- data/lib/barker/repo.rb +6 -0
- data/lib/barker/round.rb +68 -0
- data/lib/barker/stage.rb +38 -0
- data/lib/barker/store/memory.rb +158 -0
- data/lib/barker/store.rb +6 -0
- data/lib/barker/validations.rb +14 -0
- data/lib/barker/version.rb +3 -0
- data/lib/barker.rb +45 -0
- data/test/factories/answer.rb +21 -0
- data/test/factories/candidate.rb +23 -0
- data/test/factories/candidate_answer.rb +12 -0
- data/test/factories/candidate_joker.rb +8 -0
- data/test/factories/candidate_question.rb +16 -0
- data/test/factories/candidate_round.rb +8 -0
- data/test/factories/game_show.rb +12 -0
- data/test/factories/joker.rb +5 -0
- data/test/factories/question.rb +13 -0
- data/test/factories/quiz.rb +11 -0
- data/test/factories/round.rb +12 -0
- data/test/factories/stage.rb +12 -0
- data/test/fixtures/questions.yaml +20 -0
- data/test/test_helper.rb +72 -0
- data/test/test_mocks.rb +21 -0
- data/test/unit/answer_test.rb +49 -0
- data/test/unit/api/base_test.rb +207 -0
- data/test/unit/api/response/base_test.rb +35 -0
- data/test/unit/api/response/candidate_answer_test.rb +64 -0
- data/test/unit/api/response/candidate_joker_test.rb +60 -0
- data/test/unit/api/response/candidate_question_test.rb +99 -0
- data/test/unit/api/response/candidate_test.rb +82 -0
- data/test/unit/api/response/game_show_test.rb +105 -0
- data/test/unit/api/response/round_test.rb +49 -0
- data/test/unit/candidate_answer_test.rb +66 -0
- data/test/unit/candidate_question_test.rb +277 -0
- data/test/unit/candidate_round_test.rb +64 -0
- data/test/unit/candidate_test.rb +76 -0
- data/test/unit/game_show_test.rb +372 -0
- data/test/unit/guideline/base_test.rb +34 -0
- data/test/unit/guideline/llmcquiz_test.rb +35 -0
- data/test/unit/guideline/mock_test.rb +33 -0
- data/test/unit/import/yaml_test.rb +41 -0
- data/test/unit/joker_test.rb +32 -0
- data/test/unit/question_test.rb +55 -0
- data/test/unit/quiz_test.rb +37 -0
- data/test/unit/repo/memory/game_show_test.rb +54 -0
- data/test/unit/round_test.rb +167 -0
- data/test/unit/stage_test.rb +53 -0
- metadata +283 -0
@@ -0,0 +1,300 @@
|
|
1
|
+
1:
|
2
|
+
label:
|
3
|
+
de: Wann ist der SuperCode nach Kauf einlösbar?
|
4
|
+
answers:
|
5
|
+
1:
|
6
|
+
correct: false
|
7
|
+
label:
|
8
|
+
de: 10 Minuten
|
9
|
+
2:
|
10
|
+
correct: true
|
11
|
+
label:
|
12
|
+
de: 30 Minuten
|
13
|
+
3:
|
14
|
+
correct: false
|
15
|
+
label:
|
16
|
+
de: 5 Minuten
|
17
|
+
4:
|
18
|
+
correct: false
|
19
|
+
label:
|
20
|
+
de: sofort
|
21
|
+
2:
|
22
|
+
label:
|
23
|
+
de: Wo kann man seit dem 1. Mai 2013 seinen SuperCode einlösen?
|
24
|
+
answers:
|
25
|
+
1:
|
26
|
+
correct: false
|
27
|
+
label:
|
28
|
+
de: In der e-va Lounge
|
29
|
+
2:
|
30
|
+
correct: false
|
31
|
+
label:
|
32
|
+
de: Auf der e-va Website
|
33
|
+
3:
|
34
|
+
correct: true
|
35
|
+
label:
|
36
|
+
de: Auf Facebook
|
37
|
+
4:
|
38
|
+
correct: false
|
39
|
+
label:
|
40
|
+
de: Direkt bei der Verkaufsstelle
|
41
|
+
3:
|
42
|
+
label:
|
43
|
+
de: Welche Geschenkkarte gibt es im e-va Sortiment?
|
44
|
+
answers:
|
45
|
+
1:
|
46
|
+
correct: true
|
47
|
+
label:
|
48
|
+
de: OBI-Geschenkkarte
|
49
|
+
2:
|
50
|
+
correct: false
|
51
|
+
label:
|
52
|
+
de: PayPal-Geschenkkarte
|
53
|
+
3:
|
54
|
+
correct: false
|
55
|
+
label:
|
56
|
+
de: Taxi-Geschenkkarte
|
57
|
+
4:
|
58
|
+
correct: false
|
59
|
+
label:
|
60
|
+
de: H&M-Geschenkkarte
|
61
|
+
4:
|
62
|
+
label:
|
63
|
+
de: Was kostet eine FYVE Sprach-Flatrate?
|
64
|
+
answers:
|
65
|
+
1:
|
66
|
+
correct: false
|
67
|
+
label:
|
68
|
+
de: 50 Euro
|
69
|
+
2:
|
70
|
+
correct: false
|
71
|
+
label:
|
72
|
+
de: 35 Euro
|
73
|
+
3:
|
74
|
+
correct: false
|
75
|
+
label:
|
76
|
+
de: 44 Euro
|
77
|
+
4:
|
78
|
+
correct: true
|
79
|
+
label:
|
80
|
+
de: 20 Euro
|
81
|
+
5:
|
82
|
+
label:
|
83
|
+
de: Welcher Berufsgruppe gehört das Testimonial von Fyve an?
|
84
|
+
answers:
|
85
|
+
1:
|
86
|
+
correct: true
|
87
|
+
label:
|
88
|
+
de: Krankenschwester
|
89
|
+
2:
|
90
|
+
correct: false
|
91
|
+
label:
|
92
|
+
de: Müllmann
|
93
|
+
3:
|
94
|
+
correct: false
|
95
|
+
label:
|
96
|
+
de: Lehrer
|
97
|
+
4:
|
98
|
+
correct: false
|
99
|
+
label:
|
100
|
+
de: Versicherungsvertreter
|
101
|
+
6:
|
102
|
+
label:
|
103
|
+
de: Welche vier Schwestern beantworten Deine Fragen zu FYVE?
|
104
|
+
answers:
|
105
|
+
1:
|
106
|
+
correct: false
|
107
|
+
label:
|
108
|
+
de: "Eva, Julia, Anna und Steffi"
|
109
|
+
2:
|
110
|
+
correct: true
|
111
|
+
label:
|
112
|
+
de: "Julia, Marie, Olga und Lucy"
|
113
|
+
3:
|
114
|
+
correct: false
|
115
|
+
label:
|
116
|
+
de: "Kate, Olga, Tanja und Maria"
|
117
|
+
4:
|
118
|
+
correct: false
|
119
|
+
label:
|
120
|
+
de: "Julia, Kim, Sophie und Eva"
|
121
|
+
7:
|
122
|
+
label:
|
123
|
+
de: Welches zusätzlich wählbares Tarif-Paket gibt es nicht bei FYVE?
|
124
|
+
answers:
|
125
|
+
1:
|
126
|
+
correct: false
|
127
|
+
label:
|
128
|
+
de: Minuten-Paket
|
129
|
+
2:
|
130
|
+
correct: false
|
131
|
+
label:
|
132
|
+
de: Surf-Paket
|
133
|
+
3:
|
134
|
+
correct: false
|
135
|
+
label:
|
136
|
+
de: SMS-Paket
|
137
|
+
4:
|
138
|
+
correct: true
|
139
|
+
label:
|
140
|
+
de: App-Paket
|
141
|
+
8:
|
142
|
+
label:
|
143
|
+
de: Wieviel muss man pro Minute und pro SMS in alle deutschen Netze bei FYVE zahlen?
|
144
|
+
answers:
|
145
|
+
1:
|
146
|
+
correct: false
|
147
|
+
label:
|
148
|
+
de: 20 Cent
|
149
|
+
2:
|
150
|
+
correct: false
|
151
|
+
label:
|
152
|
+
de: 50 Cent
|
153
|
+
3:
|
154
|
+
correct: true
|
155
|
+
label:
|
156
|
+
de: 9 Cent
|
157
|
+
4:
|
158
|
+
correct: false
|
159
|
+
label:
|
160
|
+
de: 15 Cent
|
161
|
+
9:
|
162
|
+
label:
|
163
|
+
de: Welches Netz nutzt man mit FYVE?
|
164
|
+
answers:
|
165
|
+
1:
|
166
|
+
correct: false
|
167
|
+
label:
|
168
|
+
de: E-Plus Netz
|
169
|
+
2:
|
170
|
+
correct: true
|
171
|
+
label:
|
172
|
+
de: Vodafone Netz
|
173
|
+
3:
|
174
|
+
correct: false
|
175
|
+
label:
|
176
|
+
de: O2 Netz
|
177
|
+
4:
|
178
|
+
correct: false
|
179
|
+
label:
|
180
|
+
de: Telekom Netz
|
181
|
+
10:
|
182
|
+
label:
|
183
|
+
de: Wofür ist die FYVE Micro-SIM-Karte?
|
184
|
+
answers:
|
185
|
+
1:
|
186
|
+
correct: true
|
187
|
+
label:
|
188
|
+
de: Für Smartphones und Tablets
|
189
|
+
2:
|
190
|
+
correct: false
|
191
|
+
label:
|
192
|
+
de: Für Digitalkameras
|
193
|
+
3:
|
194
|
+
correct: false
|
195
|
+
label:
|
196
|
+
de: Für Notebook und Surfstick
|
197
|
+
4:
|
198
|
+
correct: false
|
199
|
+
label:
|
200
|
+
de: Für MP3-Player
|
201
|
+
11:
|
202
|
+
label:
|
203
|
+
de: Für 9 Cent kann man ebenfalls in wie viele ausländische Festnetze telefonieren?
|
204
|
+
answers:
|
205
|
+
1:
|
206
|
+
correct: false
|
207
|
+
label:
|
208
|
+
de: 10
|
209
|
+
2:
|
210
|
+
correct: true
|
211
|
+
label:
|
212
|
+
de: 33
|
213
|
+
3:
|
214
|
+
correct: false
|
215
|
+
label:
|
216
|
+
de: 20
|
217
|
+
4:
|
218
|
+
correct: false
|
219
|
+
label:
|
220
|
+
de: 15
|
221
|
+
12:
|
222
|
+
label:
|
223
|
+
de: Aus wie vielen Tarif-Paketen kann man bei FYVE wählen?
|
224
|
+
answers:
|
225
|
+
1:
|
226
|
+
correct: false
|
227
|
+
label:
|
228
|
+
de: Aus über 3
|
229
|
+
2:
|
230
|
+
correct: false
|
231
|
+
label:
|
232
|
+
de: Aus über 5
|
233
|
+
3:
|
234
|
+
correct: false
|
235
|
+
label:
|
236
|
+
de: Aus über 7
|
237
|
+
4:
|
238
|
+
correct: true
|
239
|
+
label:
|
240
|
+
de: Aus über 10
|
241
|
+
13:
|
242
|
+
label:
|
243
|
+
de: FYVE ist die Lösung aus…?
|
244
|
+
answers:
|
245
|
+
1:
|
246
|
+
correct: false
|
247
|
+
label:
|
248
|
+
de: dem Tarifdschungel
|
249
|
+
2:
|
250
|
+
correct: false
|
251
|
+
label:
|
252
|
+
de: der Tarifhölle
|
253
|
+
3:
|
254
|
+
correct: true
|
255
|
+
label:
|
256
|
+
de: dem Tarifwahnsinn
|
257
|
+
4:
|
258
|
+
correct: false
|
259
|
+
label:
|
260
|
+
de: dem Tarifchaos
|
261
|
+
14:
|
262
|
+
label:
|
263
|
+
de: Welche Auflade-Wertstufen erhält man an e-va Stationen für FYVE?
|
264
|
+
answers:
|
265
|
+
1:
|
266
|
+
correct: true
|
267
|
+
label:
|
268
|
+
de: 15 und 25 Euro
|
269
|
+
2:
|
270
|
+
correct: false
|
271
|
+
label:
|
272
|
+
de: 15, 20 und 30 Euro
|
273
|
+
3:
|
274
|
+
correct: false
|
275
|
+
label:
|
276
|
+
de: 20 und 30 Euro
|
277
|
+
4:
|
278
|
+
correct: false
|
279
|
+
label:
|
280
|
+
de: 10, 20 und 30 Euro
|
281
|
+
15:
|
282
|
+
label:
|
283
|
+
de: Mit welchem Aufladeguthaben kann man die FYVE SIM-Karte aufladen?
|
284
|
+
answers:
|
285
|
+
1:
|
286
|
+
correct: true
|
287
|
+
label:
|
288
|
+
de: FYVE und Vodafone
|
289
|
+
2:
|
290
|
+
correct: false
|
291
|
+
label:
|
292
|
+
de: Telekom
|
293
|
+
3:
|
294
|
+
correct: false
|
295
|
+
label:
|
296
|
+
de: Lebara
|
297
|
+
4:
|
298
|
+
correct: false
|
299
|
+
label:
|
300
|
+
de: O2
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Barker
|
2
|
+
module Guideline
|
3
|
+
|
4
|
+
class Llmcquiz < Base
|
5
|
+
|
6
|
+
def quizzes
|
7
|
+
[Quiz.new(questions.sample(5))]
|
8
|
+
end
|
9
|
+
|
10
|
+
def jokers
|
11
|
+
['fifty_fifty']
|
12
|
+
end
|
13
|
+
|
14
|
+
def questions
|
15
|
+
Barker::Import::Yaml.process(path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def round_time
|
19
|
+
35
|
20
|
+
end
|
21
|
+
|
22
|
+
def path
|
23
|
+
File.expand_path "#{File.dirname(__FILE__)}/../../../lib/barker/guideline/llmcquiz/questions.yaml"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Barker
|
2
|
+
module Import
|
3
|
+
class Yaml
|
4
|
+
|
5
|
+
include Errors
|
6
|
+
|
7
|
+
def self.process(path)
|
8
|
+
raise FileNotExistError unless File.exist? path
|
9
|
+
|
10
|
+
questions = YAML.load(File.read(path))
|
11
|
+
|
12
|
+
questions.map do |id, question|
|
13
|
+
answers = question["answers"].map do |id, answer|
|
14
|
+
Answer.new(id, answer["label"], answer["correct"])
|
15
|
+
end
|
16
|
+
Question.new(id, question["label"], answers)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/barker/joker.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Barker
|
2
|
+
class Joker
|
3
|
+
attr_reader :id
|
4
|
+
|
5
|
+
def initialize(id)
|
6
|
+
@id = id
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(candidate_question)
|
10
|
+
"Barker::Jokers::#{id.to_s.classify}".constantize.call(candidate_question)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Barker
|
16
|
+
module Jokers
|
17
|
+
class FiftyFifty
|
18
|
+
def self.call(candidate_question)
|
19
|
+
amount = candidate_question.answers.size / 2
|
20
|
+
wrong_answers = candidate_question.answers.reject {|a| a.correct? }
|
21
|
+
|
22
|
+
amount.times do |i|
|
23
|
+
wrong_answers[i].try(:reveal)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/barker/quiz.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Barker
|
2
|
+
module Repo
|
3
|
+
module Memory
|
4
|
+
class GameShow
|
5
|
+
|
6
|
+
include Errors
|
7
|
+
|
8
|
+
def add(game_show)
|
9
|
+
store.add game_show
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(game_show_id)
|
13
|
+
store.get(game_show_id.to_s) || raise(RecordNotFound)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(game_show)
|
17
|
+
store.update game_show
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove(game_show)
|
21
|
+
store.remove(game_show)
|
22
|
+
end
|
23
|
+
|
24
|
+
def around(game_show_id)
|
25
|
+
game_show = store.get game_show_id.to_s
|
26
|
+
yield game_show
|
27
|
+
store.update game_show
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def store
|
32
|
+
@store ||= Barker::Store::Memory.new(:id, :build_key => true)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/barker/repo.rb
ADDED
data/lib/barker/round.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Barker
|
2
|
+
class Round
|
3
|
+
attr_reader :question, :candidates, :started_at, :finished_at, :guideline
|
4
|
+
|
5
|
+
def initialize(question, candidates, options = {})
|
6
|
+
@question = question
|
7
|
+
@candidates = candidates
|
8
|
+
@started_at = nil
|
9
|
+
@finished_at = nil
|
10
|
+
@guideline = options[:guideline]
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
question.valid? && candidates.any?
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
@started_at = Time.now unless started?
|
19
|
+
end
|
20
|
+
|
21
|
+
def started?
|
22
|
+
!!started_at
|
23
|
+
end
|
24
|
+
|
25
|
+
def finish
|
26
|
+
@finished_at = Time.now unless finished?
|
27
|
+
end
|
28
|
+
|
29
|
+
def finished?
|
30
|
+
!!finished_at
|
31
|
+
end
|
32
|
+
|
33
|
+
def running?
|
34
|
+
started? && !finished?
|
35
|
+
end
|
36
|
+
|
37
|
+
def ask(candidate_id, options = {})
|
38
|
+
candidate_round(candidate_id).ask(options)
|
39
|
+
end
|
40
|
+
|
41
|
+
# replace answer_index with answer_uid
|
42
|
+
def answer(candidate_id, answer_index)
|
43
|
+
candidate_round(candidate_id).answer(answer_index)
|
44
|
+
end
|
45
|
+
|
46
|
+
def given_answer(candidate_id)
|
47
|
+
candidate_round(candidate_id).given_answer
|
48
|
+
end
|
49
|
+
|
50
|
+
def joker(candidate, joker)
|
51
|
+
candidate_round(candidate.id).joker(joker)
|
52
|
+
end
|
53
|
+
|
54
|
+
# TODO: Refactor below
|
55
|
+
def candidate_round(candidate_id)
|
56
|
+
candidate_rounds[candidate_id]
|
57
|
+
end
|
58
|
+
|
59
|
+
def candidate_rounds
|
60
|
+
@candidate_rounds ||= Hash[candidates.map { |candidate| [candidate.id, CandidateRound.new(candidate, self, :guideline => guideline)] }]
|
61
|
+
end
|
62
|
+
|
63
|
+
def candidate_questions
|
64
|
+
candidates.map { |candidate| candidate_round(candidate.id).question }
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/lib/barker/stage.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Barker
|
2
|
+
class Stage
|
3
|
+
|
4
|
+
attr_reader :quiz, :candidates, :guideline
|
5
|
+
|
6
|
+
def initialize(quiz, candidates, options = {})
|
7
|
+
@quiz = quiz
|
8
|
+
@candidates = candidates
|
9
|
+
@round_counter = -1
|
10
|
+
@guideline = options[:guideline]
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
quiz.valid? && candidates.any?
|
15
|
+
end
|
16
|
+
|
17
|
+
def rounds
|
18
|
+
@rounds ||= quiz.questions.map { |question| Barker::Round.new(question, candidates, :guideline => guideline) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_round
|
22
|
+
round_counter != -1 && rounds[round_counter]
|
23
|
+
end
|
24
|
+
|
25
|
+
def next_round
|
26
|
+
@round_counter += 1
|
27
|
+
end
|
28
|
+
|
29
|
+
def next_round?
|
30
|
+
!!rounds[round_counter + 1]
|
31
|
+
end
|
32
|
+
|
33
|
+
def round_counter
|
34
|
+
@round_counter
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|