battleroom 0.0.2x → 0.0.3
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 +4 -4
- data/lib/battleroom/data/{data_structure_questions.rb → array_questions.rb} +1 -60
- data/lib/battleroom/data/hash_questions.rb +63 -0
- data/lib/battleroom/data/nested_data_structure_access_questions.rb +26 -0
- data/lib/battleroom/models/array_access_question.rb +19 -0
- data/lib/battleroom/models/array_assignment_question.rb +91 -0
- data/lib/battleroom/models/data_structure_assignment_question.rb +50 -0
- data/lib/battleroom/models/hash_access_question.rb +31 -0
- data/lib/battleroom/models/hash_assignment_question.rb +38 -0
- data/lib/battleroom/models/nested_data_structure_access_question.rb +19 -0
- data/lib/battleroom/models/variable_question.rb +63 -0
- data/lib/battleroom.rb +6 -3
- metadata +14 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c68abc679f13da1a621073aca8a602f5a9286308
|
4
|
+
data.tar.gz: 84726ceed2983a20e8b40c54f593695ac8eae42e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c334740b7e5c250e0307ee836ec9a4fe262ef55f41440e1cf683fbc235de128604c0c3769283bdebcdde02cb2a685af7b35095757da880f5576703e19ee3631
|
7
|
+
data.tar.gz: 06d615176abf29da1cd9243f861c0b6626fcc136bbf02a6b016643320f4e0be9aa57ac3277cbd1b013e0fd572717a4b8f6b1efe02afc9c52bc4aba3a1df4595d
|
@@ -2,28 +2,9 @@ require 'pry'
|
|
2
2
|
# eliminates deprecation warning
|
3
3
|
I18n.config.enforce_available_locales = false
|
4
4
|
|
5
|
-
require_relative '../data_generation_machinery'
|
6
|
-
include DataGenerationMachinery
|
7
|
-
require 'active_support/inflector'
|
8
|
-
|
9
5
|
$random_names_array = gen_random_names_array
|
10
6
|
|
11
|
-
|
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
|
-
},
|
7
|
+
ARRAY_QUESTIONS = [
|
27
8
|
{
|
28
9
|
data_structure: [
|
29
10
|
'Foundation',
|
@@ -202,27 +183,6 @@ DATA_STRUCTURE_QUESTIONS = [
|
|
202
183
|
'fab_four_tunes',
|
203
184
|
].shuffle,
|
204
185
|
},
|
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
186
|
{
|
227
187
|
data_structure: [
|
228
188
|
'When Harry Met Sally',
|
@@ -293,22 +253,3 @@ DATA_STRUCTURE_QUESTIONS = [
|
|
293
253
|
].shuffle
|
294
254
|
},
|
295
255
|
]
|
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,63 @@
|
|
1
|
+
require_relative '../data_generation_machinery'
|
2
|
+
include DataGenerationMachinery
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
HASH_QUESTIONS = [
|
6
|
+
{
|
7
|
+
data_structure: {
|
8
|
+
home_team: 'Green Bay Packers',
|
9
|
+
capacity: 72_928,
|
10
|
+
established: 1957,
|
11
|
+
publicly_owned: true,
|
12
|
+
real_grass: true,
|
13
|
+
price_of_beer: 5.5,
|
14
|
+
namesake: 'Curly Lambeau',
|
15
|
+
address: '1265 Lombardi',
|
16
|
+
suite_count: 168,
|
17
|
+
banners: true,
|
18
|
+
},
|
19
|
+
possible_variable_names: ['lambeau_field', 'the_frozen_tundra'],
|
20
|
+
},
|
21
|
+
{
|
22
|
+
data_structure: {
|
23
|
+
stars: ['Ryan Gosling', 'Rachel McAdams'],
|
24
|
+
released: 2004,
|
25
|
+
tearjerker: true,
|
26
|
+
director: 'Nick Cassavetes',
|
27
|
+
mtv_movie_award_count: 1,
|
28
|
+
box_office_millions: 81.5,
|
29
|
+
macho: false,
|
30
|
+
},
|
31
|
+
possible_variable_names: ['the_notebook'],
|
32
|
+
},
|
33
|
+
{
|
34
|
+
data_structure: {
|
35
|
+
stars: ['Nicholas Cage', 'Meryl Streep'],
|
36
|
+
rt_rating: 98.0,
|
37
|
+
released: 2002,
|
38
|
+
screenwriters: ['Charlie Kaufman', 'Donald Kaufman'],
|
39
|
+
},
|
40
|
+
possible_variable_names: ['adaptation'],
|
41
|
+
},
|
42
|
+
]
|
43
|
+
|
44
|
+
HASH_QUESTIONS
|
45
|
+
|
46
|
+
5.times do
|
47
|
+
user = gen_user
|
48
|
+
HASH_QUESTIONS.push(user)
|
49
|
+
business = gen_business
|
50
|
+
HASH_QUESTIONS.push(business)
|
51
|
+
end
|
52
|
+
|
53
|
+
4.times do
|
54
|
+
location = gen_location
|
55
|
+
HASH_QUESTIONS.push(location)
|
56
|
+
end
|
57
|
+
|
58
|
+
2.times do
|
59
|
+
app = gen_app
|
60
|
+
HASH_QUESTIONS.push(app)
|
61
|
+
end
|
62
|
+
|
63
|
+
HASH_QUESTIONS.shuffle!
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# things to consider
|
2
|
+
# some should start as arrays, others as hashes
|
3
|
+
# is awesome_print the best solution?
|
4
|
+
# I should keep whatever data structures I create brief
|
5
|
+
# I should keep the first key-value pair of a hash to simple datatypes. the second k-v pair should be the nested data structure
|
6
|
+
# key lengths should be close, for readability (keep in mind this is for absolute beginners)
|
7
|
+
|
8
|
+
NESTED_DATA_STRUCTURE_ACCESS_QUESTIONS = [
|
9
|
+
{
|
10
|
+
data_structure: [
|
11
|
+
{ title: 'The Stone Roses', released: 1989 },
|
12
|
+
{ title: 'Second Coming', released: 1994 },
|
13
|
+
],
|
14
|
+
possible_variable_names: ['stone_roses_albums']
|
15
|
+
},
|
16
|
+
{
|
17
|
+
data_structure: [
|
18
|
+
{ song_title: 'Material Girl', billboard_peak: 2 },
|
19
|
+
{ song_title: 'Borderline', billboard_peak: 10 },
|
20
|
+
{ song_title: 'Lucky Star', billboard_peak: 4 },
|
21
|
+
{ song_title: 'Holiday', billboard_peak: 16 },
|
22
|
+
{ song_title: 'Vogue', billboard_peak: 1 },
|
23
|
+
],
|
24
|
+
possible_variable_names: ['madonna_singles']
|
25
|
+
}
|
26
|
+
]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../data/array_questions'
|
2
|
+
require_relative './data_structure_access_question'
|
3
|
+
|
4
|
+
class ArrayAccessQuestion < DataStructureAccessQuestion
|
5
|
+
|
6
|
+
@questions = ARRAY_QUESTIONS.shuffle
|
7
|
+
|
8
|
+
def initialize(scope)
|
9
|
+
super(scope)
|
10
|
+
format_array_for_access
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_array_for_access
|
14
|
+
self.data_structure = data_structure[0, rand(4..6)]
|
15
|
+
self.answer_value = data_structure.sample
|
16
|
+
self.hint = 'index values start at 0.'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative '../data/array_questions'
|
2
|
+
require_relative './data_structure_assignment_question'
|
3
|
+
|
4
|
+
class ArrayAssignmentQuestion < DataStructureAssignmentQuestion
|
5
|
+
|
6
|
+
@questions = ARRAY_QUESTIONS
|
7
|
+
|
8
|
+
def initialize(scope)
|
9
|
+
super(scope)
|
10
|
+
format_array_for_assignment
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_array_for_assignment
|
14
|
+
desired_array_size = rand(3..6)
|
15
|
+
cull_array_to_valid_size_for_output(desired_array_size)
|
16
|
+
if [1, 2, 3, 4, 5].sample.odd?
|
17
|
+
self.value_to_replace = data_structure.sample
|
18
|
+
self.value_to_replace_formatted = format_value_for_stdout_and_eval(value_to_replace)
|
19
|
+
end
|
20
|
+
self.assignment_value = possible_assignments.sample
|
21
|
+
self.assignment_value_class = format_class_for_output(assignment_value.class)
|
22
|
+
self.formatted_assignment_value = format_value_for_stdout_and_eval(assignment_value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def cull_array_to_valid_size_for_output(desired_size)
|
26
|
+
while data_structure.size > desired_size
|
27
|
+
new_assignment_possibility = data_structure.delete(data_structure.sample)
|
28
|
+
possible_assignments.push(new_assignment_possibility)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_replace_array_value_prompt
|
33
|
+
puts "Given the data structure below, replace the #{replacement_value_class_formatted} value ".blue +
|
34
|
+
value_to_replace_formatted.yellow + " with the #{assignment_value_class} value ".blue +
|
35
|
+
formatted_assignment_value.yellow + ".\n\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
def print_data_structure_assignment_prompt
|
39
|
+
if value_to_replace
|
40
|
+
self.replacement_index = data_structure.index(value_to_replace)
|
41
|
+
self.replacement_value_class_formatted = format_class_for_output(value_to_replace.class)
|
42
|
+
print_replace_array_value_prompt
|
43
|
+
else
|
44
|
+
puts "Use an array method to add the #{assignment_value_class} value ".blue + "#{formatted_assignment_value}".yellow + " to the ".blue + "end".blue.underline + " of the Array below.\n".blue
|
45
|
+
end
|
46
|
+
print "#{variable_name} = ".green
|
47
|
+
ap(data_structure, { indent: -2, index: false, multiline: true, plain: true })
|
48
|
+
puts ''
|
49
|
+
end
|
50
|
+
|
51
|
+
def handle_replacement_of_array_value_input(user_input)
|
52
|
+
if evaluation_scope.eval("#{variable_name}[#{replacement_index}] == #{formatted_assignment_value}") && user_input.include?(variable_name)
|
53
|
+
print_resulting_data_structure
|
54
|
+
true
|
55
|
+
else
|
56
|
+
puts "\nNope! Here's what the data stucture would look like given your code:\n".red
|
57
|
+
resulting_data_structure = evaluation_scope.eval(variable_name)
|
58
|
+
ap(resulting_data_structure, { indent: -2, index: false, multiline: true, plain: true })
|
59
|
+
puts "\nCheck your index and assignment values and try again.\n".red
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def handles_user_workarounds(user_input)
|
64
|
+
cheater_regex = Regexp.new("#{variable_name}\s+?\=\s+?(\\[)?")
|
65
|
+
# checks if user reassigned the variable to a new array of identical values
|
66
|
+
if user_input.match(cheater_regex)
|
67
|
+
if $1
|
68
|
+
puts 'You reassigned the variable to a new array object, when you could have worked with the array provided! Look up Ruby\'s Array#push method and try again!'.red
|
69
|
+
else
|
70
|
+
puts 'You reassigned the variable '.red + variable_name.green + ' rather than working with the array provided. Try again.'.red
|
71
|
+
end
|
72
|
+
puts ''
|
73
|
+
true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def evaluate_user_input(user_input)
|
78
|
+
if handles_user_workarounds(user_input)
|
79
|
+
false
|
80
|
+
end
|
81
|
+
if value_to_replace
|
82
|
+
handle_replacement_of_array_value_input(user_input)
|
83
|
+
elsif evaluation_scope.eval("#{variable_name}.last == #{formatted_assignment_value}") && user_input.include?(variable_name)
|
84
|
+
print_resulting_data_structure
|
85
|
+
true
|
86
|
+
else
|
87
|
+
puts 'Nope! Try again.'.red
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative './data_structure_question'
|
2
|
+
|
3
|
+
class DataStructureAssignmentQuestion < DataStructureQuestion
|
4
|
+
|
5
|
+
attr_accessor :assignment_value, :assignment_key, :assignment_value_class,
|
6
|
+
:formatted_assignment_value, :value_to_replace,
|
7
|
+
:value_to_replace_formatted, :replacement_index,
|
8
|
+
:replacement_value_class_formatted
|
9
|
+
|
10
|
+
def initialize(eval_scope)
|
11
|
+
super(eval_scope)
|
12
|
+
end
|
13
|
+
|
14
|
+
def print_resulting_data_structure
|
15
|
+
possible_intro_congratulations = [
|
16
|
+
'Brilliant',
|
17
|
+
'Wonderful',
|
18
|
+
'Jackpot',
|
19
|
+
'Impressive work',
|
20
|
+
'Bang-up job',
|
21
|
+
'Dynamite',
|
22
|
+
'Premier work',
|
23
|
+
'Quality work',
|
24
|
+
'Terrific'
|
25
|
+
]
|
26
|
+
intro_congrat = possible_intro_congratulations.sample
|
27
|
+
puts "\n#{intro_congrat}. Here's the resulting data structure:\n".green
|
28
|
+
sleep 1.0
|
29
|
+
resulting_data_structure = evaluation_scope.eval(variable_name)
|
30
|
+
ap(resulting_data_structure, { indent: -2, index: false, multiline: true, plain: true })
|
31
|
+
puts ''
|
32
|
+
sleep 3.2
|
33
|
+
end
|
34
|
+
|
35
|
+
def evaluate_data_structure_assignment_input
|
36
|
+
enter_evaluation_loop do |user_input|
|
37
|
+
begin
|
38
|
+
# provides the evaluation scope with variable assignment necessary for answer eval
|
39
|
+
evaluation_scope.eval("#{variable_name} = #{data_structure.to_s}")
|
40
|
+
evaluation_scope.eval(user_input)
|
41
|
+
evaluate_user_input(user_input)
|
42
|
+
rescue NoMethodError, NameError => e
|
43
|
+
print_colorized_error_prompt(e)
|
44
|
+
rescue TypeError => e
|
45
|
+
print_colorized_type_error_prompt(e)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../data/hash_questions'
|
2
|
+
require_relative './data_structure_access_question'
|
3
|
+
|
4
|
+
class HashAccessQuestion < DataStructureAccessQuestion
|
5
|
+
|
6
|
+
@questions = HASH_QUESTIONS.shuffle
|
7
|
+
|
8
|
+
def initialize(scope)
|
9
|
+
super(scope)
|
10
|
+
format_hash
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_hash
|
14
|
+
cull_hash_to_valid_size_for_output
|
15
|
+
remove_multiple_booleans
|
16
|
+
self.answer_value = data_structure[data_structure.keys.sample]
|
17
|
+
self.hint = 'you have to use the EXACT hash key to retrieve the associated value.'
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove_multiple_booleans
|
21
|
+
boolean_count = find_number_of_boolean_values_in_hash
|
22
|
+
while boolean_count > 1
|
23
|
+
grouped_by_value = data_structure.group_by { |k, v| v }
|
24
|
+
boolean_to_delete = [true, false].sample
|
25
|
+
key_to_delete = grouped_by_value[boolean_to_delete].sample[0] if grouped_by_value[boolean_to_delete]
|
26
|
+
data_structure.delete(key_to_delete)
|
27
|
+
boolean_count = find_number_of_boolean_values_in_hash
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../data/hash_questions'
|
2
|
+
require_relative './data_structure_access_question'
|
3
|
+
|
4
|
+
class HashAssignmentQuestion < DataStructureAssignmentQuestion
|
5
|
+
|
6
|
+
@questions = HASH_QUESTIONS.shuffle
|
7
|
+
|
8
|
+
def initialize(scope)
|
9
|
+
super(scope)
|
10
|
+
format_hash_for_assignment
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_hash_for_assignment
|
14
|
+
cull_hash_to_valid_size_for_output
|
15
|
+
assignment = possible_assignments.sample
|
16
|
+
self.assignment_value = assignment.values[0]
|
17
|
+
self.assignment_value_class = format_class_for_output(assignment_value.class)
|
18
|
+
self.formatted_assignment_value = format_value_for_stdout_and_eval(assignment_value)
|
19
|
+
self.assignment_key = format_value_for_stdout_and_eval(assignment.keys[0])
|
20
|
+
end
|
21
|
+
|
22
|
+
def print_data_structure_assignment_prompt
|
23
|
+
puts 'Given the Hash below, add a key of '.blue + assignment_key.yellow + " that points to the #{assignment_value_class} value of ".blue + "#{formatted_assignment_value}".yellow + ".\n\n"
|
24
|
+
print "#{variable_name} = ".green
|
25
|
+
ap(data_structure, { indent: -2, index: false, multiline: true, plain: true })
|
26
|
+
puts ''
|
27
|
+
end
|
28
|
+
|
29
|
+
def evaluate_user_input(user_input)
|
30
|
+
if evaluation_scope.eval("#{variable_name}[#{assignment_key}] == #{formatted_assignment_value}") && user_input.include?(variable_name)
|
31
|
+
print_resulting_data_structure
|
32
|
+
true
|
33
|
+
else
|
34
|
+
puts 'Nope! Try again!'.red
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'data_structure_access_question'
|
2
|
+
require_relative '../data/nested_data_structure_access_questions'
|
3
|
+
|
4
|
+
class NestedDataStructureAccessQuestion < DataStructureAccessQuestion
|
5
|
+
attr_accessor :inner_hash, :inner_array
|
6
|
+
# class instance variable used within the initialize method for Question
|
7
|
+
@questions = NESTED_DATA_STRUCTURE_ACCESS_QUESTIONS.shuffle
|
8
|
+
|
9
|
+
def initialize(eval_scope)
|
10
|
+
super(eval_scope)
|
11
|
+
if data_structure.class == Array
|
12
|
+
self.inner_hash = data_structure.sample
|
13
|
+
self.answer_value = inner_hash[inner_hash.keys.sample]
|
14
|
+
else
|
15
|
+
self.answer_value = data_structure[data_structure.keys.sample]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative 'question'
|
2
|
+
require_relative '../data/variable_assignment_questions'
|
3
|
+
|
4
|
+
class VariableQuestion < Question
|
5
|
+
attr_accessor :formatted_value
|
6
|
+
# using a class instance variable, as manipulating a single class var
|
7
|
+
# in the parent class is troublesome
|
8
|
+
@questions = VARIABLE_QUESTIONS.shuffle
|
9
|
+
|
10
|
+
def initialize(eval_scope)
|
11
|
+
super(eval_scope)
|
12
|
+
@variable_value = rotate_array(data[:possible_variable_values]).first
|
13
|
+
@formatted_value = format_value_for_stdout_and_eval(variable_value)
|
14
|
+
end
|
15
|
+
|
16
|
+
def print_variable_assignment_prompt
|
17
|
+
formatted_class = format_class_for_output(variable_value.class)
|
18
|
+
substrings = [
|
19
|
+
'Create a variable '.blue,
|
20
|
+
variable_name.yellow,
|
21
|
+
' and assign it the '.blue,
|
22
|
+
formatted_class.blue,
|
23
|
+
' value '.blue,
|
24
|
+
formatted_value.yellow
|
25
|
+
]
|
26
|
+
puts substrings.join
|
27
|
+
end
|
28
|
+
|
29
|
+
def reveal_name_error_follies_to_user(user_input)
|
30
|
+
if user_input.include?(variable_name) && !user_input.match(/[^=]=[^=]/i)
|
31
|
+
puts 'You\'re not using the assignment operator!'.red
|
32
|
+
elsif !user_input.match(/("|')/) && variable_value.class == String
|
33
|
+
puts 'Rats! You\'ve just made a common rookie mistake! ' +
|
34
|
+
'Strings are always surrounded by quotes. Otherwise, Ruby will ' +
|
35
|
+
'think you\'re referencing a variable or method name. Try again.'.red
|
36
|
+
else
|
37
|
+
puts 'Looks like you mistyped the variable name. Check for misspellings and try again.'.red
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def evaluate_variable_assignment_input
|
42
|
+
enter_evaluation_loop do |user_input|
|
43
|
+
begin
|
44
|
+
evaluation_scope.eval(user_input)
|
45
|
+
if evaluation_scope.eval("#{variable_name} == #{formatted_value}")
|
46
|
+
# this last returned value of 'true' is vital;
|
47
|
+
# the return value of yield is used in a conditional
|
48
|
+
true
|
49
|
+
else
|
50
|
+
puts "You mis-assigned #{variable_name}. Try again!".red
|
51
|
+
end
|
52
|
+
rescue NameError => e
|
53
|
+
reveal_name_error_follies_to_user(user_input)
|
54
|
+
rescue Exception => e
|
55
|
+
if e.message.match(/unterminated string/)
|
56
|
+
puts 'Blurg! You neglected to provide closing quotes for your string. Try again!'.red
|
57
|
+
else
|
58
|
+
puts e.message
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end # VariableQuestion
|
data/lib/battleroom.rb
CHANGED
@@ -9,7 +9,10 @@ require 'Faker'
|
|
9
9
|
|
10
10
|
require_relative './battleroom/models/nested_data_structure_access_question'
|
11
11
|
require_relative './battleroom/models/data_structure_assignment_question'
|
12
|
-
require_relative './battleroom/models/
|
12
|
+
require_relative './battleroom/models/hash_access_question'
|
13
|
+
require_relative './battleroom/models/hash_assignment_question'
|
14
|
+
require_relative './battleroom/models/array_access_question'
|
15
|
+
require_relative './battleroom/models/array_assignment_question'
|
13
16
|
require_relative './battleroom/models/variable_question'
|
14
17
|
|
15
18
|
require_relative 'battleroom/battleroom_machinery'
|
@@ -36,13 +39,13 @@ loop do
|
|
36
39
|
end
|
37
40
|
when '2'
|
38
41
|
5.times do
|
39
|
-
q =
|
42
|
+
q = [ArrayAccessQuestion.new(b), HashAccessQuestion.new(b)].sample
|
40
43
|
q.print_data_structure_access_prompt
|
41
44
|
q.evaluate_data_structure_access_input
|
42
45
|
end
|
43
46
|
when '3'
|
44
47
|
5.times do
|
45
|
-
q =
|
48
|
+
q = [ArrayAssignmentQuestion.new(b), HashAssignmentQuestion.new(b)].sample
|
46
49
|
q.print_data_structure_assignment_prompt
|
47
50
|
q.evaluate_data_structure_assignment_input
|
48
51
|
end
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Vander Hoop
|
@@ -60,8 +60,17 @@ files:
|
|
60
60
|
- bin/battleroom
|
61
61
|
- lib/battleroom.rb
|
62
62
|
- lib/battleroom/battleroom_machinery.rb
|
63
|
-
- lib/battleroom/data/
|
63
|
+
- lib/battleroom/data/array_questions.rb
|
64
|
+
- lib/battleroom/data/hash_questions.rb
|
65
|
+
- lib/battleroom/data/nested_data_structure_access_questions.rb
|
64
66
|
- lib/battleroom/data/variable_assignment_questions.rb
|
67
|
+
- lib/battleroom/models/array_access_question.rb
|
68
|
+
- lib/battleroom/models/array_assignment_question.rb
|
69
|
+
- lib/battleroom/models/data_structure_assignment_question.rb
|
70
|
+
- lib/battleroom/models/hash_access_question.rb
|
71
|
+
- lib/battleroom/models/hash_assignment_question.rb
|
72
|
+
- lib/battleroom/models/nested_data_structure_access_question.rb
|
73
|
+
- lib/battleroom/models/variable_question.rb
|
65
74
|
homepage: https://github.com/vanderhoop/battleroom
|
66
75
|
licenses:
|
67
76
|
- MIT
|
@@ -74,12 +83,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
83
|
requirements:
|
75
84
|
- - ">="
|
76
85
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
86
|
+
version: 1.9.3
|
78
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
88
|
requirements:
|
80
|
-
- - "
|
89
|
+
- - ">="
|
81
90
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
91
|
+
version: '0'
|
83
92
|
requirements: []
|
84
93
|
rubyforge_project:
|
85
94
|
rubygems_version: 2.2.2
|