barker 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.simplecov +7 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +50 -0
  8. data/LICENSE +22 -0
  9. data/README.md +204 -0
  10. data/Rakefile +12 -0
  11. data/barker.gemspec +29 -0
  12. data/ci/run +20 -0
  13. data/lib/barker/answer.rb +11 -0
  14. data/lib/barker/api/base.rb +145 -0
  15. data/lib/barker/api/response/base.rb +25 -0
  16. data/lib/barker/api/response/candidate.rb +38 -0
  17. data/lib/barker/api/response/candidate_answer.rb +23 -0
  18. data/lib/barker/api/response/candidate_joker.rb +21 -0
  19. data/lib/barker/api/response/candidate_question.rb +51 -0
  20. data/lib/barker/api/response/error.rb +17 -0
  21. data/lib/barker/api/response/game_show.rb +43 -0
  22. data/lib/barker/api/response/round.rb +21 -0
  23. data/lib/barker/api/response.rb +15 -0
  24. data/lib/barker/api.rb +7 -0
  25. data/lib/barker/candidate.rb +52 -0
  26. data/lib/barker/candidate_answer.rb +42 -0
  27. data/lib/barker/candidate_joker.rb +30 -0
  28. data/lib/barker/candidate_question.rb +116 -0
  29. data/lib/barker/candidate_round.rb +32 -0
  30. data/lib/barker/entity.rb +15 -0
  31. data/lib/barker/game_show.rb +176 -0
  32. data/lib/barker/guideline/base.rb +33 -0
  33. data/lib/barker/guideline/llmcquiz/questions.yaml +300 -0
  34. data/lib/barker/guideline/llmcquiz.rb +28 -0
  35. data/lib/barker/guideline/mock.rb +17 -0
  36. data/lib/barker/guideline.rb +8 -0
  37. data/lib/barker/import/yaml.rb +22 -0
  38. data/lib/barker/import.rb +6 -0
  39. data/lib/barker/joker.rb +28 -0
  40. data/lib/barker/question.rb +12 -0
  41. data/lib/barker/quiz.rb +19 -0
  42. data/lib/barker/repo/memory/game_show.rb +38 -0
  43. data/lib/barker/repo/memory.rb +8 -0
  44. data/lib/barker/repo.rb +6 -0
  45. data/lib/barker/round.rb +68 -0
  46. data/lib/barker/stage.rb +38 -0
  47. data/lib/barker/store/memory.rb +158 -0
  48. data/lib/barker/store.rb +6 -0
  49. data/lib/barker/validations.rb +14 -0
  50. data/lib/barker/version.rb +3 -0
  51. data/lib/barker.rb +45 -0
  52. data/test/factories/answer.rb +21 -0
  53. data/test/factories/candidate.rb +23 -0
  54. data/test/factories/candidate_answer.rb +12 -0
  55. data/test/factories/candidate_joker.rb +8 -0
  56. data/test/factories/candidate_question.rb +16 -0
  57. data/test/factories/candidate_round.rb +8 -0
  58. data/test/factories/game_show.rb +12 -0
  59. data/test/factories/joker.rb +5 -0
  60. data/test/factories/question.rb +13 -0
  61. data/test/factories/quiz.rb +11 -0
  62. data/test/factories/round.rb +12 -0
  63. data/test/factories/stage.rb +12 -0
  64. data/test/fixtures/questions.yaml +20 -0
  65. data/test/test_helper.rb +72 -0
  66. data/test/test_mocks.rb +21 -0
  67. data/test/unit/answer_test.rb +49 -0
  68. data/test/unit/api/base_test.rb +207 -0
  69. data/test/unit/api/response/base_test.rb +35 -0
  70. data/test/unit/api/response/candidate_answer_test.rb +64 -0
  71. data/test/unit/api/response/candidate_joker_test.rb +60 -0
  72. data/test/unit/api/response/candidate_question_test.rb +99 -0
  73. data/test/unit/api/response/candidate_test.rb +82 -0
  74. data/test/unit/api/response/game_show_test.rb +105 -0
  75. data/test/unit/api/response/round_test.rb +49 -0
  76. data/test/unit/candidate_answer_test.rb +66 -0
  77. data/test/unit/candidate_question_test.rb +277 -0
  78. data/test/unit/candidate_round_test.rb +64 -0
  79. data/test/unit/candidate_test.rb +76 -0
  80. data/test/unit/game_show_test.rb +372 -0
  81. data/test/unit/guideline/base_test.rb +34 -0
  82. data/test/unit/guideline/llmcquiz_test.rb +35 -0
  83. data/test/unit/guideline/mock_test.rb +33 -0
  84. data/test/unit/import/yaml_test.rb +41 -0
  85. data/test/unit/joker_test.rb +32 -0
  86. data/test/unit/question_test.rb +55 -0
  87. data/test/unit/quiz_test.rb +37 -0
  88. data/test/unit/repo/memory/game_show_test.rb +54 -0
  89. data/test/unit/round_test.rb +167 -0
  90. data/test/unit/stage_test.rb +53 -0
  91. 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,17 @@
1
+ require 'factory_girl'
2
+
3
+ module Barker
4
+ module Guideline
5
+
6
+ class Mock < Base
7
+ def quizzes
8
+ [FactoryGirl.build(:quiz)]
9
+ end
10
+
11
+ def jokers
12
+ ['fifty_fifty']
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'barker/guideline/base'
2
+ require 'barker/guideline/mock'
3
+ require 'barker/guideline/llmcquiz'
4
+
5
+ module Barker
6
+ module Guideline
7
+ end
8
+ 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
@@ -0,0 +1,6 @@
1
+ require 'barker/import/yaml'
2
+
3
+ module Barker
4
+ module Import
5
+ end
6
+ end
@@ -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
@@ -0,0 +1,12 @@
1
+ module Barker
2
+ class Question < Entity.new(:id, :label, :answers)
3
+
4
+ include Barker::Validations::NumericalityOfId
5
+
6
+ alias :_valid? :valid?
7
+ def valid?
8
+ _valid? && answers.all?(&:valid?)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Barker
2
+ class Quiz
3
+
4
+ attr_reader :questions
5
+
6
+ def initialize(questions)
7
+ @questions = questions
8
+ end
9
+
10
+ def valid?
11
+ questions.all?(&:valid?)
12
+ end
13
+
14
+ def ==(other)
15
+ questions == other.questions
16
+ end
17
+
18
+ end
19
+ end
@@ -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
@@ -0,0 +1,8 @@
1
+ require 'barker/repo/memory/game_show'
2
+
3
+ module Barker
4
+ module Repo
5
+ module Memory
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ require 'barker/repo/memory'
2
+
3
+ module Barker
4
+ module Repo
5
+ end
6
+ end
@@ -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
@@ -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