battleroom 0.0.0 → 0.0.2x
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/battleroom +0 -82
- data/lib/battleroom/battleroom_machinery.rb +89 -6
- data/lib/battleroom/data/data_structure_questions.rb +314 -0
- data/lib/battleroom/data/variable_assignment_questions.rb +159 -0
- data/lib/battleroom.rb +39 -70
- metadata +46 -6
- data/lib/battleroom/question_data/data_structure_access.rb +0 -82
- data/lib/battleroom/question_data/variable_assignment.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b95c630774eac85f4874d405bc1a6fd8b80f5ef
|
4
|
+
data.tar.gz: bf928ca6a161a73ebc9e6f72e8c488ef727b06d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5477c37f8c00484bde29ac86c9cd70fb956a3111ac1e0364e474d24d0ba9ce3a2094dcfd00e13144ad452fcdd45509093805cc9cc794269a8d06d44d1723a1c3
|
7
|
+
data.tar.gz: cb1ffc7deab34ed6947cbd7600562ace7ca6546e473ce08757d164bbbd736a3ef6fb22fc0e9a91158a6d8a883a8b5c5587132726d7c67d6144a8ccd84930c59d
|
data/bin/battleroom
CHANGED
@@ -1,85 +1,3 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'battleroom'
|
4
|
-
|
5
|
-
# clear_display
|
6
|
-
# print "Welcome to the Battleroom.".blue
|
7
|
-
# while true
|
8
|
-
# print_prompt_with_options
|
9
|
-
# choice = gets.chomp.downcase
|
10
|
-
# clear_display
|
11
|
-
|
12
|
-
# # for eval
|
13
|
-
# b = binding
|
14
|
-
|
15
|
-
# case choice
|
16
|
-
# when "1"
|
17
|
-
# 10.times do
|
18
|
-
# question = VARIABLE_QUESTIONS.sample
|
19
|
-
# var_name = question[:var_name].sample
|
20
|
-
# var_value = question[:var_value].sample
|
21
|
-
# puts "Create a variable, #{var_name}, and assign it the #{question[:value_type]} value #{var_value}".blue
|
22
|
-
# answered_correctly = false
|
23
|
-
# until answered_correctly
|
24
|
-
# answer = gets.chomp
|
25
|
-
# begin
|
26
|
-
# b.eval(answer)
|
27
|
-
# if b.eval("#{var_name} == #{var_value}")
|
28
|
-
# answered_correctly = true
|
29
|
-
# puts random_congratulation.green
|
30
|
-
# else
|
31
|
-
# print "You mis-assigned #{var_name}. ".red + "Try Again!\n".green
|
32
|
-
# end
|
33
|
-
# rescue NameError
|
34
|
-
# print "Looks like you misnamed your variable. Often this will result in an error that says: \n\n".red
|
35
|
-
# print "\tundefined local variable or method \'WHATEVER_YOU_MISTYPED\'\n\n".green
|
36
|
-
# puts "Try again.".red
|
37
|
-
# rescue Exception => e
|
38
|
-
# puts e.message
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
# when "2"
|
43
|
-
# 5.times do
|
44
|
-
# question = DATA_STRUCTURE_QUESTIONS.sample
|
45
|
-
# data_structure = question[:data_structure]
|
46
|
-
# if data_structure.class == Array
|
47
|
-
# answer_value = data_structure.sample
|
48
|
-
# hint = "index values start at 0."
|
49
|
-
# else
|
50
|
-
# answer_value = data_structure[data_structure.keys.sample]
|
51
|
-
# hint = "you have to use the EXACT hash key to retrieve the associated value."
|
52
|
-
# end
|
53
|
-
# answer_value = data_structure.class == Array ? data_structure.sample : data_structure[data_structure.keys.sample]
|
54
|
-
# # data_structure_binding = binding
|
55
|
-
# # provides the binding scope with the variable assignment necessary for future
|
56
|
-
# b.eval("#{question[:variable_name]} = #{question[:data_structure].to_s}")
|
57
|
-
# puts "Given the data structure below, how would you access '#{answer_value}'?".blue
|
58
|
-
# puts "#{question[:variable_name]} = #{question[:data_structure].to_s}".green
|
59
|
-
# answered_correctly = false
|
60
|
-
# until answered_correctly
|
61
|
-
# input = gets.chomp
|
62
|
-
# begin
|
63
|
-
# if b.eval(input) == answer_value
|
64
|
-
# puts random_congratulation.green
|
65
|
-
# answered_correctly = true
|
66
|
-
# sleep 1.5
|
67
|
-
# clear_display
|
68
|
-
# else
|
69
|
-
# puts "Wrong. Remember, #{hint} Try again.".red
|
70
|
-
# end
|
71
|
-
# rescue NameError
|
72
|
-
# puts "You're referencing a variable that doesn't exist, probably as the result of a mispelling. This results in a common error that says: \n\n".red
|
73
|
-
# puts "\tundefined local variable or method \'WHATEVER_YOU_MISTYPED\'\n".green
|
74
|
-
# puts "Get used to it and try again.".red
|
75
|
-
# end
|
76
|
-
# end
|
77
|
-
# end
|
78
|
-
# when "q"
|
79
|
-
# puts "Goodbye!".green
|
80
|
-
# break
|
81
|
-
# else
|
82
|
-
# puts "You entered a non-option. Try again.".red
|
83
|
-
# end
|
84
|
-
# end
|
85
|
-
|
@@ -1,18 +1,101 @@
|
|
1
|
+
require 'awesome_print'
|
2
|
+
require 'pry'
|
3
|
+
require 'colorize'
|
4
|
+
|
1
5
|
module BattleroomMachinery
|
2
6
|
|
7
|
+
CONGRATULATIONS = [
|
8
|
+
'Lovely work, my friend!',
|
9
|
+
'Beautiful!',
|
10
|
+
'Lovely!',
|
11
|
+
'Splendid!',
|
12
|
+
'Nice job! Keep it rolling!',
|
13
|
+
'Capital work, battlestar!',
|
14
|
+
'Exemplary work!',
|
15
|
+
'Yeah!',
|
16
|
+
'Roll on.',
|
17
|
+
'Bullseye!',
|
18
|
+
'Woo!',
|
19
|
+
'Let it ride!',
|
20
|
+
'Touchdown!',
|
21
|
+
"You're on your way!",
|
22
|
+
"You're making a prosperous go of this programming thing.",
|
23
|
+
]
|
24
|
+
|
3
25
|
def clear_display
|
4
26
|
`reset`
|
5
27
|
end
|
6
28
|
|
29
|
+
def print_menu_options
|
30
|
+
puts ' What would you like to work on?'.blue
|
31
|
+
puts '1. Variable assignment'
|
32
|
+
puts '2. Accessing values in arrays and hashes'
|
33
|
+
puts '3. Adding values to arrays and hashes'
|
34
|
+
puts '4. Accessing values from within nested data structures'
|
35
|
+
puts "Q. Quit\r\n\n"
|
36
|
+
end
|
37
|
+
|
7
38
|
def random_congratulation
|
8
|
-
|
39
|
+
CONGRATULATIONS.sample
|
9
40
|
end
|
10
41
|
|
11
|
-
def
|
12
|
-
puts "
|
13
|
-
|
14
|
-
|
15
|
-
|
42
|
+
def print_congratulation
|
43
|
+
puts "#{random_congratulation}\n".green
|
44
|
+
end
|
45
|
+
|
46
|
+
def rotate_array(array)
|
47
|
+
item = array.shift
|
48
|
+
array << item
|
49
|
+
end
|
50
|
+
|
51
|
+
def print_colorized_error_prompt(error)
|
52
|
+
method_or_variable = (error.class == NoMethodError) ? "method" : "variable"
|
53
|
+
puts "\nYou're referencing a #{method_or_variable} that doesn't exist, probably as the result of a mispelling. This results in a common error that says: \n".red
|
54
|
+
puts "\tundefined local variable or method \'WHATEVER_YOU_MISTYPED\'\n".green
|
55
|
+
puts "Get used to it and try again.\n".red
|
16
56
|
end
|
17
57
|
|
58
|
+
def print_unexpected_end_of_input_explanation
|
59
|
+
puts "\nNope! You just triggered a common Ruby error that reads:\n".red
|
60
|
+
puts "\tsyntax error, unexpected end-of-input\n".green
|
61
|
+
puts "Basically, you told Ruby you were going to assign a value to a variable, but you neglected to provide a valid value. Try again.\n".red
|
62
|
+
end
|
63
|
+
|
64
|
+
def print_colorized_type_error_prompt(error)
|
65
|
+
puts "\nNope! You just triggered a common Ruby error that reads:\n".red
|
66
|
+
puts "\tin '[]', #{error.message}".green
|
67
|
+
error.message.match /conversion\sof\s(.+)\sinto\sInteger/i
|
68
|
+
puts "\nBasically, you put a #{$1} between square brackets, whereas Ruby ".red +
|
69
|
+
"was expecting an index value, i.e. an integer. This commonly arises ".red +
|
70
|
+
"when programmers think they're dealing with a hash, when in fact ".red +
|
71
|
+
"they're dealing with an array. Try again.\n".red
|
72
|
+
end
|
73
|
+
|
74
|
+
def format_value_for_stdout_and_eval(object)
|
75
|
+
case object.class.to_s
|
76
|
+
when 'String'
|
77
|
+
if object.include?("'")
|
78
|
+
'"' + object + '"'
|
79
|
+
else
|
80
|
+
"'#{object}'"
|
81
|
+
end
|
82
|
+
when 'Symbol' then return ":#{object}"
|
83
|
+
else
|
84
|
+
object.to_s
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def naughty_input?(user_input)
|
89
|
+
if user_input.match(/(require|`|binding)/)
|
90
|
+
puts "No way no how! Try again.\n".red
|
91
|
+
true
|
92
|
+
else
|
93
|
+
false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def format_class_for_output(klass)
|
98
|
+
return 'Boolean' if klass.to_s.match /(TrueClass|FalseClass)/
|
99
|
+
klass.to_s
|
100
|
+
end
|
18
101
|
end
|
@@ -0,0 +1,314 @@
|
|
1
|
+
require 'pry'
|
2
|
+
# eliminates deprecation warning
|
3
|
+
I18n.config.enforce_available_locales = false
|
4
|
+
|
5
|
+
require_relative '../data_generation_machinery'
|
6
|
+
include DataGenerationMachinery
|
7
|
+
require 'active_support/inflector'
|
8
|
+
|
9
|
+
$random_names_array = gen_random_names_array
|
10
|
+
|
11
|
+
DATA_STRUCTURE_QUESTIONS = [
|
12
|
+
{
|
13
|
+
data_structure: {
|
14
|
+
home_team: 'Green Bay Packers',
|
15
|
+
capacity: 72_928,
|
16
|
+
established: 1957,
|
17
|
+
publicly_owned: true,
|
18
|
+
real_grass: true,
|
19
|
+
price_of_beer: 5.5,
|
20
|
+
namesake: 'Curly Lambeau',
|
21
|
+
address: '1265 Lombardi',
|
22
|
+
suite_count: 168,
|
23
|
+
banners: true,
|
24
|
+
},
|
25
|
+
possible_variable_names: ['lambeau_field', 'the_frozen_tundra'],
|
26
|
+
},
|
27
|
+
{
|
28
|
+
data_structure: [
|
29
|
+
'Foundation',
|
30
|
+
'American Gods',
|
31
|
+
'The Gunslinger',
|
32
|
+
'Do Androids Dream of Electric Sheep?',
|
33
|
+
'A Scanner Darkly',
|
34
|
+
'We Can Build You',
|
35
|
+
'Dune',
|
36
|
+
'The Left Hand of Darkness',
|
37
|
+
'Stranger in a Strange Land',
|
38
|
+
'Sirens of Titan',
|
39
|
+
'Brave New World',
|
40
|
+
'Lord of the Rings',
|
41
|
+
'1984',
|
42
|
+
'Farhenheit 451',
|
43
|
+
'Animal Farm',
|
44
|
+
'Watchmen',
|
45
|
+
'The Stand',
|
46
|
+
'2001',
|
47
|
+
'Starship Troopers',
|
48
|
+
'The Time Machine',
|
49
|
+
"Hitchhiker's Guide to the Galaxy",
|
50
|
+
"Cat's Cradle",
|
51
|
+
"Ender's Game",
|
52
|
+
],
|
53
|
+
possible_variable_names: [
|
54
|
+
'sci_fi_books',
|
55
|
+
'sci_fi_novels',
|
56
|
+
'canonical_sci_fi_titles',
|
57
|
+
'science_fiction_titles',
|
58
|
+
'books',
|
59
|
+
'paperback_titles',
|
60
|
+
].shuffle,
|
61
|
+
},
|
62
|
+
{
|
63
|
+
data_structure: $random_names_array,
|
64
|
+
possible_variable_names: [
|
65
|
+
'friends',
|
66
|
+
'enemies',
|
67
|
+
'co_workers',
|
68
|
+
'old_pals',
|
69
|
+
'new_friends',
|
70
|
+
'frenemies',
|
71
|
+
'lovers',
|
72
|
+
'admirers',
|
73
|
+
'haters',
|
74
|
+
'stalker_names'
|
75
|
+
].shuffle,
|
76
|
+
},
|
77
|
+
{
|
78
|
+
data_structure: (7..29).to_a.shuffle,
|
79
|
+
possible_variable_names: [
|
80
|
+
'fav_nums',
|
81
|
+
'lotto_nums',
|
82
|
+
'ages_of_children',
|
83
|
+
'favorite_years_of_life',
|
84
|
+
'career_jersey_numbers',
|
85
|
+
'lucky_numbers',
|
86
|
+
'unlucky_numbers'
|
87
|
+
].shuffle,
|
88
|
+
},
|
89
|
+
{
|
90
|
+
data_structure: [
|
91
|
+
rand(0.0..100.0).round(2),
|
92
|
+
rand(0.0..100.0).round(2),
|
93
|
+
rand(0.0..100.0).round(2),
|
94
|
+
rand(0.0..100.0).round(2),
|
95
|
+
rand(0.0..100.0).round(2),
|
96
|
+
rand(0.0..100.0).round(2),
|
97
|
+
rand(0.0..100.0).round(2),
|
98
|
+
rand(0.0..100.0).round(2),
|
99
|
+
rand(0.0..100.0).round(2),
|
100
|
+
rand(0.0..100.0).round(2),
|
101
|
+
rand(0.0..100.0).round(2),
|
102
|
+
rand(0.0..100.0).round(2),
|
103
|
+
rand(0.0..100.0).round(2),
|
104
|
+
rand(0.0..100.0).round(2),
|
105
|
+
rand(0.0..100.0).round(2),
|
106
|
+
rand(0.0..100.0).round(2),
|
107
|
+
rand(0.0..100.0).round(2),
|
108
|
+
rand(0.0..100.0).round(2),
|
109
|
+
rand(0.0..100.0).round(2),
|
110
|
+
rand(0.0..100.0).round(2),
|
111
|
+
rand(0.0..100.0).round(2),
|
112
|
+
rand(0.0..100.0).round(2),
|
113
|
+
rand(0.0..100.0).round(2),
|
114
|
+
rand(0.0..100.0).round(2),
|
115
|
+
rand(0.0..100.0).round(2),
|
116
|
+
].uniq,
|
117
|
+
possible_variable_names: [
|
118
|
+
'test_scores',
|
119
|
+
'win_percentages',
|
120
|
+
'yield_percentages',
|
121
|
+
'dividends',
|
122
|
+
'multiples',
|
123
|
+
'sums',
|
124
|
+
'products',
|
125
|
+
'monthly_bill_totals'
|
126
|
+
].shuffle,
|
127
|
+
},
|
128
|
+
{
|
129
|
+
data_structure: [
|
130
|
+
'Patches',
|
131
|
+
'Falstaff',
|
132
|
+
'Whiskers',
|
133
|
+
'Trousers',
|
134
|
+
'Sammycat',
|
135
|
+
'Dunbar',
|
136
|
+
'Digsy',
|
137
|
+
'Bubs',
|
138
|
+
'Davy',
|
139
|
+
'Tomcat',
|
140
|
+
'Mr. Bigglesworth',
|
141
|
+
'Pinot',
|
142
|
+
'Claude',
|
143
|
+
'Jackson',
|
144
|
+
'Bootsniffer',
|
145
|
+
'Frank',
|
146
|
+
'Dogboy',
|
147
|
+
'Kittyhawk',
|
148
|
+
'Kitty the Cat',
|
149
|
+
'Tiny',
|
150
|
+
],
|
151
|
+
possible_variable_names: [
|
152
|
+
'cat_names',
|
153
|
+
'cats',
|
154
|
+
'kitties',
|
155
|
+
'felines',
|
156
|
+
'kittie_names'
|
157
|
+
].shuffle,
|
158
|
+
},
|
159
|
+
{
|
160
|
+
data_structure: [
|
161
|
+
'Fixing a Hole',
|
162
|
+
'Michelle',
|
163
|
+
'Hey Jude',
|
164
|
+
'In My Life',
|
165
|
+
'A Day in the Life',
|
166
|
+
'If I Needed Someone',
|
167
|
+
'Nowhere Man',
|
168
|
+
'Dear Prudence',
|
169
|
+
'Julia',
|
170
|
+
'Good Night',
|
171
|
+
'Something',
|
172
|
+
'Sun King',
|
173
|
+
'Carry That Weight',
|
174
|
+
'Girl',
|
175
|
+
'What Goes On',
|
176
|
+
'The Word',
|
177
|
+
'Blackbird',
|
178
|
+
'Piggies',
|
179
|
+
'Rocky Racoon',
|
180
|
+
'Cry Baby Cry',
|
181
|
+
'Taxman',
|
182
|
+
'Eleanor Rigby',
|
183
|
+
'Yellow Submarine',
|
184
|
+
'Only a Northern Song',
|
185
|
+
'Mean Mr. Mustard',
|
186
|
+
'All My Loving',
|
187
|
+
'Norwegian Wood',
|
188
|
+
'Yesterday',
|
189
|
+
'Blue Jay Way',
|
190
|
+
'Hello, Goodbye',
|
191
|
+
'Penny Lane',
|
192
|
+
'All You Need is Love',
|
193
|
+
'The Fool on the Hill',
|
194
|
+
"I'm So Tired",
|
195
|
+
"I'm Only Sleeping",
|
196
|
+
"I'll Follow the Sun",
|
197
|
+
"I'm Looking Through You",
|
198
|
+
],
|
199
|
+
possible_variable_names: [
|
200
|
+
'beatles_songs',
|
201
|
+
'fav_beatles_tracks',
|
202
|
+
'fab_four_tunes',
|
203
|
+
].shuffle,
|
204
|
+
},
|
205
|
+
{
|
206
|
+
data_structure: {
|
207
|
+
stars: ['Ryan Gosling', 'Rachel McAdams'],
|
208
|
+
released: 2004,
|
209
|
+
tearjerker: true,
|
210
|
+
director: 'Nick Cassavetes',
|
211
|
+
mtv_movie_award_count: 1,
|
212
|
+
box_office_millions: 81.5,
|
213
|
+
macho: false,
|
214
|
+
},
|
215
|
+
possible_variable_names: ['the_notebook'],
|
216
|
+
},
|
217
|
+
{
|
218
|
+
data_structure: {
|
219
|
+
stars: ['Nicholas Cage', 'Meryl Streep'],
|
220
|
+
rt_rating: 98.0,
|
221
|
+
released: 2002,
|
222
|
+
screenwriters: ['Charlie Kaufman', 'Donald Kaufman'],
|
223
|
+
},
|
224
|
+
possible_variable_names: ['adaptation'],
|
225
|
+
},
|
226
|
+
{
|
227
|
+
data_structure: [
|
228
|
+
'When Harry Met Sally',
|
229
|
+
'How to Lose a Guy in 10 Days',
|
230
|
+
'Bridesmaids',
|
231
|
+
'Knocked Up',
|
232
|
+
'High Fidelity',
|
233
|
+
'Chasing Amy',
|
234
|
+
'What Women Want',
|
235
|
+
'Four Weddings and a Funeral',
|
236
|
+
'About a Boy',
|
237
|
+
'Notting Hill',
|
238
|
+
'His Girl Friday',
|
239
|
+
"America's Sweethearts",
|
240
|
+
"My Best Friend's Wedding",
|
241
|
+
"There's Something About Mary",
|
242
|
+
],
|
243
|
+
possible_variable_names: ['rom_coms']
|
244
|
+
},
|
245
|
+
{
|
246
|
+
data_structure: [
|
247
|
+
'The Moon and Antarctica',
|
248
|
+
'Perfect From Now On',
|
249
|
+
'Nighthawks at the Diner',
|
250
|
+
'Songs From a Room',
|
251
|
+
'Transformer',
|
252
|
+
'Songs of Love and Hate',
|
253
|
+
'Stereopathetic Soul Manure',
|
254
|
+
"Frank's Wild Years",
|
255
|
+
],
|
256
|
+
possible_variable_names: [
|
257
|
+
'lyrically_brilliant_albums',
|
258
|
+
'seminal_indie_rock_records'
|
259
|
+
].shuffle
|
260
|
+
},
|
261
|
+
{
|
262
|
+
data_structure: [
|
263
|
+
'Sixteen Stone',
|
264
|
+
'Nirvana MTV Unplugged 1994',
|
265
|
+
'Jagged Little Pill',
|
266
|
+
'Ten',
|
267
|
+
'Nevermind',
|
268
|
+
'Illmatic',
|
269
|
+
'The Downward Spiral',
|
270
|
+
'Odelay',
|
271
|
+
'Mellowgold',
|
272
|
+
'All Eyez On Me',
|
273
|
+
'Ready 2 Die',
|
274
|
+
'Blur',
|
275
|
+
'Parklife',
|
276
|
+
'Definitely Maybe',
|
277
|
+
'Keep It Like a Secret',
|
278
|
+
'...Come Down',
|
279
|
+
'XO',
|
280
|
+
'Exile in Guyville',
|
281
|
+
'The Lonesome Crowded West',
|
282
|
+
'Crooked Rain, Crooked Rain',
|
283
|
+
'The Blue Album',
|
284
|
+
'Pinkerton',
|
285
|
+
'OK Computer',
|
286
|
+
'The Bends',
|
287
|
+
'Slanted & Enchanted',
|
288
|
+
"What's the Story (Morning Glory)?",
|
289
|
+
],
|
290
|
+
possible_variable_names: [
|
291
|
+
'classics_from_the_nineties',
|
292
|
+
'nineties_classics',
|
293
|
+
].shuffle
|
294
|
+
},
|
295
|
+
]
|
296
|
+
|
297
|
+
5.times do
|
298
|
+
user = gen_user
|
299
|
+
DATA_STRUCTURE_QUESTIONS.push(user)
|
300
|
+
business = gen_business
|
301
|
+
DATA_STRUCTURE_QUESTIONS.push(business)
|
302
|
+
end
|
303
|
+
|
304
|
+
4.times do
|
305
|
+
location = gen_location
|
306
|
+
DATA_STRUCTURE_QUESTIONS.push(location)
|
307
|
+
end
|
308
|
+
|
309
|
+
2.times do
|
310
|
+
app = gen_app
|
311
|
+
DATA_STRUCTURE_QUESTIONS.push(app)
|
312
|
+
end
|
313
|
+
|
314
|
+
DATA_STRUCTURE_QUESTIONS.shuffle!
|
@@ -0,0 +1,159 @@
|
|
1
|
+
VARIABLE_QUESTIONS = [
|
2
|
+
# {
|
3
|
+
# possible_variable_names: [
|
4
|
+
# "sampled_key"
|
5
|
+
# ],
|
6
|
+
# possible_variable_values: [
|
7
|
+
# :username,
|
8
|
+
# :age,
|
9
|
+
# :first_name,
|
10
|
+
# :last_name,
|
11
|
+
# :email_address,
|
12
|
+
# :album_count,
|
13
|
+
# :year_of_birth
|
14
|
+
# ]
|
15
|
+
# }
|
16
|
+
{
|
17
|
+
possible_variable_names: [
|
18
|
+
'fish_count',
|
19
|
+
'cat_count',
|
20
|
+
'user_count',
|
21
|
+
'number_of_dogs',
|
22
|
+
'num_steaks',
|
23
|
+
'fav_number',
|
24
|
+
'lucky_number',
|
25
|
+
'head_count',
|
26
|
+
'consecutive_wins',
|
27
|
+
'consecutive_losses',
|
28
|
+
'unlucky_number',
|
29
|
+
'days_without_rain',
|
30
|
+
'years_without_championship',
|
31
|
+
].shuffle,
|
32
|
+
possible_variable_values: (1..100).to_a.shuffle,
|
33
|
+
},
|
34
|
+
{
|
35
|
+
possible_variable_names: [
|
36
|
+
'signed_in',
|
37
|
+
'authenticated',
|
38
|
+
'authorized',
|
39
|
+
'heartbroken',
|
40
|
+
'ecstatic',
|
41
|
+
'admin_user',
|
42
|
+
'likes_dogs',
|
43
|
+
'takes_baths',
|
44
|
+
'can_swim',
|
45
|
+
'can_ride_a_bike',
|
46
|
+
'tells_lies',
|
47
|
+
'is_homeowner',
|
48
|
+
'password_verified',
|
49
|
+
'has_drivers_license',
|
50
|
+
'orphaned',
|
51
|
+
'steals_candy',
|
52
|
+
'has_cold',
|
53
|
+
'athletic',
|
54
|
+
'docile',
|
55
|
+
].shuffle,
|
56
|
+
possible_variable_values: [true, false].shuffle,
|
57
|
+
},
|
58
|
+
{
|
59
|
+
possible_variable_names: [
|
60
|
+
'time_abroad',
|
61
|
+
'period_married',
|
62
|
+
'waiting_period',
|
63
|
+
'sentence_length',
|
64
|
+
'tenure',
|
65
|
+
'life_span',
|
66
|
+
'term_length',
|
67
|
+
'time_in_office',
|
68
|
+
'incumbency',
|
69
|
+
'stint_length',
|
70
|
+
].shuffle,
|
71
|
+
possible_variable_values: [
|
72
|
+
'too short',
|
73
|
+
'much too long',
|
74
|
+
'None, thank god.',
|
75
|
+
'brief',
|
76
|
+
'fleeting',
|
77
|
+
'short-lived',
|
78
|
+
'everlasting',
|
79
|
+
'overlong',
|
80
|
+
'unending',
|
81
|
+
"#{rand(2..11)} months",
|
82
|
+
"#{rand(2..11)} months",
|
83
|
+
"#{rand(2..11)} months",
|
84
|
+
"#{rand(2..20)} years",
|
85
|
+
"#{rand(2..20)} years",
|
86
|
+
"#{rand(2..20)} years",
|
87
|
+
"#{rand(2..6)} days",
|
88
|
+
"#{rand(2..6)} days",
|
89
|
+
"#{rand(2..6)} days",
|
90
|
+
].uniq.shuffle,
|
91
|
+
},
|
92
|
+
{
|
93
|
+
possible_variable_names: [
|
94
|
+
'pilot_name',
|
95
|
+
'point_guard',
|
96
|
+
'gardener',
|
97
|
+
'cook',
|
98
|
+
'chef',
|
99
|
+
'boss',
|
100
|
+
'rival',
|
101
|
+
'opponent',
|
102
|
+
'foe',
|
103
|
+
'partner',
|
104
|
+
'teammate',
|
105
|
+
'collaborator',
|
106
|
+
'subordinate',
|
107
|
+
'server',
|
108
|
+
'trooper',
|
109
|
+
'peacekeeper',
|
110
|
+
'best_friend',
|
111
|
+
'worst_enemy',
|
112
|
+
'oldest_friend',
|
113
|
+
'nemesis',
|
114
|
+
'comrade',
|
115
|
+
'team_captain',
|
116
|
+
'instructor_name',
|
117
|
+
'friend_for_life',
|
118
|
+
'thief',
|
119
|
+
'dancer',
|
120
|
+
'lead_singer',
|
121
|
+
'drummer',
|
122
|
+
'guitarist',
|
123
|
+
'bassist',
|
124
|
+
].shuffle,
|
125
|
+
possible_variable_values: $random_names_array.shuffle
|
126
|
+
},
|
127
|
+
{
|
128
|
+
possible_variable_names: [
|
129
|
+
'percentage_gold',
|
130
|
+
'test_score',
|
131
|
+
'top_test_score',
|
132
|
+
'top_score',
|
133
|
+
'low_score',
|
134
|
+
'divisor',
|
135
|
+
'multiple',
|
136
|
+
'sum',
|
137
|
+
'dividend',
|
138
|
+
'total',
|
139
|
+
'share_percentage',
|
140
|
+
'percentage_gained',
|
141
|
+
'percentage_lost',
|
142
|
+
].shuffle,
|
143
|
+
possible_variable_values: [
|
144
|
+
'n/a',
|
145
|
+
rand(0.0..99.9).round([2, 3].sample),
|
146
|
+
rand(0.0..99.9).round([2, 3].sample),
|
147
|
+
rand(0.0..99.9).round([2, 3].sample),
|
148
|
+
rand(0.0..99.9).round([2, 3].sample),
|
149
|
+
rand(0.0..99.9).round([2, 3].sample),
|
150
|
+
rand(0.0..99.9).round([2, 3].sample),
|
151
|
+
rand(0.0..99.9).round([2, 3].sample),
|
152
|
+
rand(0.0..99.9).round([2, 3].sample),
|
153
|
+
rand(0.0..99.9).round([2, 3].sample),
|
154
|
+
rand(0.0..99.9).round([2, 3].sample),
|
155
|
+
rand(0.0..99.9).round([2, 3].sample),
|
156
|
+
rand(0.0..99.9).round([2, 3].sample),
|
157
|
+
].shuffle,
|
158
|
+
},
|
159
|
+
]
|
data/lib/battleroom.rb
CHANGED
@@ -1,90 +1,59 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'readline'
|
4
|
+
require 'Faker'
|
5
|
+
|
6
|
+
# the below takes forever to load(?), so resorting to multiline requiring
|
7
|
+
# path = File.expand_path("./battleroom/models/*.rb", File.dirname(__FILE__))
|
8
|
+
# Dir[path].each { |file| require file }
|
9
|
+
|
10
|
+
require_relative './battleroom/models/nested_data_structure_access_question'
|
11
|
+
require_relative './battleroom/models/data_structure_assignment_question'
|
12
|
+
require_relative './battleroom/models/data_structure_access_question'
|
13
|
+
require_relative './battleroom/models/variable_question'
|
14
|
+
|
5
15
|
require_relative 'battleroom/battleroom_machinery'
|
6
16
|
include BattleroomMachinery
|
7
|
-
require 'colorize'
|
8
|
-
require 'pry'
|
9
17
|
|
10
18
|
clear_display
|
11
|
-
print
|
12
|
-
|
13
|
-
|
14
|
-
|
19
|
+
print 'Welcome to the Battleroom.'.blue
|
20
|
+
|
21
|
+
loop do
|
22
|
+
print_menu_options
|
23
|
+
choice = Readline.readline('> '.blue, true)
|
24
|
+
abort('Goodbye!'.green) if choice.match(/^(q|exit|!!!\s?)/i)
|
15
25
|
clear_display
|
16
26
|
|
17
27
|
# for eval
|
18
28
|
b = binding
|
19
29
|
|
20
30
|
case choice
|
21
|
-
when
|
31
|
+
when '1'
|
22
32
|
10.times do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
rescue NameError
|
39
|
-
print "Looks like you misnamed your variable. Often this will result in an error that says: \n\n".red
|
40
|
-
print "\tundefined local variable or method \'WHATEVER_YOU_MISTYPED\'\n\n".green
|
41
|
-
puts "Try again.".red
|
42
|
-
rescue Exception => e
|
43
|
-
puts e.message
|
44
|
-
end
|
45
|
-
end
|
33
|
+
q = VariableQuestion.new(b)
|
34
|
+
q.print_variable_assignment_prompt
|
35
|
+
q.evaluate_variable_assignment_input
|
36
|
+
end
|
37
|
+
when '2'
|
38
|
+
5.times do
|
39
|
+
q = DataStructureAccessQuestion.new(b)
|
40
|
+
q.print_data_structure_access_prompt
|
41
|
+
q.evaluate_data_structure_access_input
|
42
|
+
end
|
43
|
+
when '3'
|
44
|
+
5.times do
|
45
|
+
q = DataStructureAssignmentQuestion.new(b)
|
46
|
+
q.print_data_structure_assignment_prompt
|
47
|
+
q.evaluate_data_structure_assignment_input
|
46
48
|
end
|
47
|
-
when
|
49
|
+
when '4'
|
48
50
|
5.times do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
answer_value = data_structure.sample
|
53
|
-
hint = "index values start at 0."
|
54
|
-
else
|
55
|
-
answer_value = data_structure[data_structure.keys.sample]
|
56
|
-
hint = "you have to use the EXACT hash key to retrieve the associated value."
|
57
|
-
end
|
58
|
-
answer_value = data_structure.class == Array ? data_structure.sample : data_structure[data_structure.keys.sample]
|
59
|
-
# data_structure_binding = binding
|
60
|
-
# provides the binding scope with the variable assignment necessary for future
|
61
|
-
b.eval("#{question[:variable_name]} = #{question[:data_structure].to_s}")
|
62
|
-
puts "Given the data structure below, how would you access '#{answer_value}'?".blue
|
63
|
-
puts "#{question[:variable_name]} = #{question[:data_structure].to_s}".green
|
64
|
-
answered_correctly = false
|
65
|
-
until answered_correctly
|
66
|
-
input = gets.chomp
|
67
|
-
begin
|
68
|
-
if b.eval(input) == answer_value
|
69
|
-
puts random_congratulation.green
|
70
|
-
answered_correctly = true
|
71
|
-
sleep 1.5
|
72
|
-
clear_display
|
73
|
-
else
|
74
|
-
puts "Wrong. Remember, #{hint} Try again.".red
|
75
|
-
end
|
76
|
-
rescue NameError
|
77
|
-
puts "You're referencing a variable that doesn't exist, probably as the result of a mispelling. This results in a common error that says: \n\n".red
|
78
|
-
puts "\tundefined local variable or method \'WHATEVER_YOU_MISTYPED\'\n".green
|
79
|
-
puts "Get used to it and try again.".red
|
80
|
-
end
|
81
|
-
end
|
51
|
+
q = NestedDataStructureAccessQuestion.new(b)
|
52
|
+
q.print_data_structure_access_prompt
|
53
|
+
q.evaluate_data_structure_access_input
|
82
54
|
end
|
83
|
-
when "q"
|
84
|
-
puts "Goodbye!".green
|
85
|
-
break
|
86
55
|
else
|
87
|
-
puts
|
56
|
+
puts 'You entered a non-option. Try again.'.red
|
88
57
|
end
|
89
58
|
end
|
90
59
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: battleroom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2x
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Vander Hoop
|
@@ -9,7 +9,47 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2010-04-28 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.7.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.7'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.7.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faker
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.3.0
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.3.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.3.0
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.3.0
|
13
53
|
description: A Battleroom
|
14
54
|
email: vanderhoop@me.com
|
15
55
|
executables:
|
@@ -20,8 +60,8 @@ files:
|
|
20
60
|
- bin/battleroom
|
21
61
|
- lib/battleroom.rb
|
22
62
|
- lib/battleroom/battleroom_machinery.rb
|
23
|
-
- lib/battleroom/
|
24
|
-
- lib/battleroom/
|
63
|
+
- lib/battleroom/data/data_structure_questions.rb
|
64
|
+
- lib/battleroom/data/variable_assignment_questions.rb
|
25
65
|
homepage: https://github.com/vanderhoop/battleroom
|
26
66
|
licenses:
|
27
67
|
- MIT
|
@@ -37,9 +77,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
77
|
version: '0'
|
38
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
79
|
requirements:
|
40
|
-
- - "
|
80
|
+
- - ">"
|
41
81
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
82
|
+
version: 1.3.1
|
43
83
|
requirements: []
|
44
84
|
rubyforge_project:
|
45
85
|
rubygems_version: 2.2.2
|
@@ -1,82 +0,0 @@
|
|
1
|
-
DATA_STRUCTURE_QUESTIONS = [
|
2
|
-
{
|
3
|
-
data_structure: ["Ender's Game", "Foundation", "Dune", "Cat's Cradle"],
|
4
|
-
variable_name: "sci_fi_books"
|
5
|
-
},
|
6
|
-
{
|
7
|
-
data_structure: ["Patches", "Falstaff", "Whiskers", "Trousers", "Sam"],
|
8
|
-
variable_name: "cat_names"
|
9
|
-
},
|
10
|
-
{
|
11
|
-
data_structure: {
|
12
|
-
num_wishes: 3,
|
13
|
-
location: ["Madison, WI", "Vancover, BC", "Denver, CO"].sample,
|
14
|
-
},
|
15
|
-
variable_name: ["genie_encounter", "meeting_with_satan_at_crossroads"].sample
|
16
|
-
},
|
17
|
-
{
|
18
|
-
data_structure: {
|
19
|
-
tiring: true,
|
20
|
-
distance: "13.1 miles",
|
21
|
-
},
|
22
|
-
variable_name: "brooklyn_half_marathon"
|
23
|
-
},
|
24
|
-
{
|
25
|
-
data_structure: ["When Harry Met Sally", "There's Something About Mary", "How to Lose a Guy in 10 Days"],
|
26
|
-
variable_name: "rom_coms"
|
27
|
-
},
|
28
|
-
{
|
29
|
-
data_structure: ["Tide", "Clorox", "Wisk", "Cheer"],
|
30
|
-
variable_name: "name_brand_detergents"
|
31
|
-
},
|
32
|
-
{
|
33
|
-
data_structure: ["The Moon and Antartica", "Frank's Wild Years", "Perfect From Now On"],
|
34
|
-
variable_name: "lyrically_brilliant_albums"
|
35
|
-
},
|
36
|
-
{
|
37
|
-
data_structure: ["Sixteen Stone", "Nirvana MTV Unplugged 1994", "Jagged Little Pill"],
|
38
|
-
variable_name: "classics_from_the_nineties"
|
39
|
-
},
|
40
|
-
{
|
41
|
-
data_structure: {
|
42
|
-
"home_team" => "Green Bay Packers",
|
43
|
-
"capacity" => 72_928,
|
44
|
-
},
|
45
|
-
variable_name: "lambeau_field"
|
46
|
-
},
|
47
|
-
{
|
48
|
-
data_structure: {
|
49
|
-
home_team: "Chicago Cubs",
|
50
|
-
capacity: 41_159,
|
51
|
-
},
|
52
|
-
variable_name: "wrigley_field"
|
53
|
-
},
|
54
|
-
{
|
55
|
-
data_structure: {
|
56
|
-
home_team: "Boston Red Sox",
|
57
|
-
capacity: 37_400,
|
58
|
-
},
|
59
|
-
variable_name: "fenway_park"
|
60
|
-
},
|
61
|
-
{
|
62
|
-
data_structure: {
|
63
|
-
stars: ["Ryan Gosling", "Rachel McAdams"],
|
64
|
-
released: 2004,
|
65
|
-
},
|
66
|
-
variable_name: "the_notebook"
|
67
|
-
},
|
68
|
-
{
|
69
|
-
data_structure: {
|
70
|
-
"stars" => ["John Cusack", "John Malkavich", "Catherine Keener"],
|
71
|
-
"released" => 1999,
|
72
|
-
},
|
73
|
-
variable_name: "being_john_malkavich"
|
74
|
-
},
|
75
|
-
{
|
76
|
-
data_structure: {
|
77
|
-
singles: ["Billie Jean", "Beat It", "Thriller"],
|
78
|
-
released: 1982,
|
79
|
-
},
|
80
|
-
variable_name: "thriller"
|
81
|
-
},
|
82
|
-
]
|
@@ -1,47 +0,0 @@
|
|
1
|
-
VARIABLE_QUESTIONS = [
|
2
|
-
{
|
3
|
-
var_name: [
|
4
|
-
"num_fish",
|
5
|
-
"num_cats",
|
6
|
-
"num_dogs",
|
7
|
-
"num_steaks",
|
8
|
-
"percent_of_love_maintained",
|
9
|
-
"fav_number",
|
10
|
-
"days_without_rain"
|
11
|
-
],
|
12
|
-
var_value: (1..100).to_a,
|
13
|
-
value_type: "FixNum"
|
14
|
-
},
|
15
|
-
{
|
16
|
-
var_name: [
|
17
|
-
"time_abroad",
|
18
|
-
"period_married",
|
19
|
-
"time_passed_since_breakup",
|
20
|
-
"time_elapsed_since_last_vacay",
|
21
|
-
"time_elapsed_since_last_title"
|
22
|
-
],
|
23
|
-
var_value: [
|
24
|
-
"'#{rand(2..11)} months'",
|
25
|
-
"'#{rand(2..20)} years'",
|
26
|
-
"'#{rand(2..3)} days'"
|
27
|
-
],
|
28
|
-
value_type: "String" },
|
29
|
-
{
|
30
|
-
var_name: [
|
31
|
-
"instructor_name",
|
32
|
-
"friend_for_life",
|
33
|
-
"super_cool_name",
|
34
|
-
"masculine_name",
|
35
|
-
"name_for_a_nice_fellow"
|
36
|
-
],
|
37
|
-
var_value: [
|
38
|
-
"'Travis'",
|
39
|
-
"'Phil'",
|
40
|
-
"'PJ'",
|
41
|
-
"'Peter'",
|
42
|
-
"'Greg'",
|
43
|
-
"'Yaniv'"
|
44
|
-
],
|
45
|
-
value_type: "String"
|
46
|
-
},
|
47
|
-
]
|