battleroom 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cf47a40ab0a46bcaf35d35d8e6084d89ef7a6fa
4
- data.tar.gz: 07aae31adc3184d72ab8e1e9efe3646149cb2cc9
3
+ metadata.gz: ff48919df45c0fb0d0f3879f628ff7923e3ea29c
4
+ data.tar.gz: 977d5f8b6317ff4f00445b488351672b2912bc02
5
5
  SHA512:
6
- metadata.gz: 878923f8f4fa845146849f6723fae748997a91c1d9a7b60726f1dea98f409ceecb4ec2e7240419f7383acd0494a5f5c2904cd6cea3197db1de0c5555e98b7ab7
7
- data.tar.gz: ef752787b94de0080f4ab21b2f2559b435464b84f678df16230e5add2bdf45e97fda790ff39519e6683858fcdb63c40a670a1a9cb0d7f478cf65ee4bd34df197
6
+ metadata.gz: 06675cdb2393c1d44004c96ab361729d5f300b2e8755da09346a803de0c03b2781ac7721fd7afe880e1a78fa6ce729fb41843d3b20d169dae055a2d82252b4be
7
+ data.tar.gz: c332c53e4ed371ecc5d4bb43af0e1b595dac4920ceab84bed26f436216341865a9ff437f1572e3c3701f8d09adcf7bcbe2c056123a2bb8fd28db327a86c3eec9
@@ -0,0 +1,154 @@
1
+ module DataGenerationMachinery
2
+
3
+ def snake_case(string)
4
+ string.downcase.gsub(',', '').gsub(' ', '_').gsub('-', '_').gsub("'", '')
5
+ end
6
+
7
+ def gen_random_names_array
8
+ random_names_array = []
9
+ 200.times { random_names_array << Faker::Name.first_name }
10
+ random_names_array.uniq
11
+ end
12
+
13
+ def gen_phone_number
14
+ "#{rand(1..9)}
15
+ #{rand(0..9)}
16
+ #{rand(0..9)}-
17
+ #{rand(0..9)}
18
+ #{rand(0..9)}
19
+ #{rand(0..9)}-
20
+ #{rand(0..9)}
21
+ #{rand(0..9)}
22
+ #{rand(0..9)}
23
+ #{rand(0..9)}".gsub(" ", "").gsub("\n", "")
24
+ end
25
+
26
+ def gen_password
27
+ possible_chars = ('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a.map(&:to_s)
28
+ possible_chars.shuffle[0, rand(6..8)].join
29
+ end
30
+
31
+ def gen_app
32
+
33
+ author_or_creator = [:author, :creator].sample
34
+ release_or_stable_release = [:release, :stable_release].sample
35
+ name_or_title = [:name, :title, :app_name].sample
36
+ name = Faker::App.name
37
+ app = {
38
+ version: Faker::App.version,
39
+ author_or_creator => Faker::App.author,
40
+ name_or_title => name,
41
+ release_or_stable_release => rand(2004..2014),
42
+ open_source: [true, false].sample
43
+ }
44
+ data = {
45
+ data_structure: app,
46
+ possible_variable_names: [
47
+ snake_case(name),
48
+ 'app',
49
+ 'application'
50
+ ].shuffle
51
+ }
52
+ end
53
+
54
+ def gen_user
55
+ password_or_pw = [:password, :pw].sample
56
+ admin_or_is_admin = [:admin, :is_admin].sample
57
+ phone_of_phone_num = [:phone, :phone_num, :phone_number].sample
58
+ occupation_or_job_title = [:occupation, :job_title].sample
59
+ zip_or_zip_code = [:zip, :zip_code].sample
60
+ first_name = Faker::Name::first_name
61
+ last_name = Faker::Name::last_name
62
+ num_string = "#{[rand(0..9), rand(0..9), rand(0..9)][0, rand(1..4)].join}"
63
+ user = {
64
+ name: first_name + ' ' + last_name,
65
+ username: Faker::Internet::user_name(first_name) + num_string,
66
+ password_or_pw => gen_password,
67
+ email: Faker::Internet.free_email(first_name),
68
+ admin_or_is_admin => [true, false].sample,
69
+ phone_of_phone_num => gen_phone_number,
70
+ accepts_marketing: [true, false].sample,
71
+ accepts_promotional_emails: [true, false].sample,
72
+ occupation_or_job_title => Faker::Name.title,
73
+ zip_or_zip_code => Faker::Address.zip
74
+ }
75
+
76
+ data = {
77
+ data_structure: user,
78
+ possible_variable_names: [
79
+ snake_case(first_name),
80
+ snake_case(first_name),
81
+ snake_case(first_name),
82
+ snake_case(first_name),
83
+ 'current_user'
84
+ ].shuffle
85
+ }
86
+ end
87
+
88
+ def gen_business_email_address(business_name)
89
+ possible_intro_words = ['info', 'hello', 'greetings', 'contact', 'team']
90
+ intro_word = possible_intro_words.sample
91
+ biz_email_address = "#{intro_word}@#{business_name.parameterize}.com"
92
+ end
93
+
94
+ def gen_business
95
+ name_or_business_name = [:name, :business_name].sample
96
+ email_key = [:email, :public_email, :info_email, :contact_email].sample
97
+ web_key = [:url, :website, :homepage_url].sample
98
+ address_key = [:street_address, :address].sample
99
+ established_key = [:established, :inception_year].sample
100
+ name = Faker::Company.name
101
+ email_address = gen_business_email_address(name)
102
+ business = {
103
+ name_or_business_name => name,
104
+ public_email: email_address,
105
+ web_key => Faker::Internet.url("#{name.parameterize}.com", ''),
106
+ phone_num: gen_phone_number,
107
+ address_key => Faker::Address.street_address,
108
+ city: Faker::Address.city,
109
+ state: Faker::Address.state_abbr,
110
+ established_key => rand(1901..2014),
111
+ }
112
+ data = {
113
+ data_structure: business,
114
+ possible_variable_names: [
115
+ snake_case(name),
116
+ snake_case(name),
117
+ snake_case(name),
118
+ 'client',
119
+ ].shuffle
120
+ }
121
+ end
122
+
123
+ def gen_location
124
+ which_key_to_use = [:short, :long].sample
125
+ latitude = { :short => :lat, :long => :latitude }
126
+ longitude = { :short => :long, :long => :longitude }
127
+ city = Faker::Address.city
128
+ population = rand(130..270000)
129
+ incorporated = population > 400 ? true : false
130
+ location = {
131
+ city: city,
132
+ population: population,
133
+ incorporated: incorporated,
134
+ livestock: [true, false].sample,
135
+ latitude[which_key_to_use] => Faker::Address.latitude.slice(0, rand(7..9)).to_f,
136
+ longitude[which_key_to_use] => Faker::Address.longitude.slice(0, rand(7..9)).to_f
137
+ }
138
+ data = {
139
+ data_structure: location,
140
+ possible_variable_names: [
141
+ snake_case(city),
142
+ 'home',
143
+ 'target',
144
+ 'destination',
145
+ 'origin',
146
+ 'locale',
147
+ 'precinct',
148
+ 'site',
149
+ ].shuffle
150
+ }
151
+ end
152
+ end
153
+
154
+
@@ -0,0 +1,41 @@
1
+ require_relative './data_structure_question'
2
+
3
+ class DataStructureAccessQuestion < DataStructureQuestion
4
+
5
+ def initialize(eval_scope)
6
+ super(eval_scope)
7
+ end
8
+
9
+ def print_data_structure_access_prompt
10
+ answer_value_class = format_class_for_output(answer_value.class)
11
+ answer_value_string = format_value_for_stdout_and_eval(answer_value)
12
+ puts "Given the data structure below, access the #{answer_value_class} value ".blue + answer_value_string.yellow + ".\n".blue
13
+ print "#{variable_name} = ".green
14
+ if data_structure.to_s.length < 40
15
+ puts data_structure.to_s.gsub('{', '{ ').gsub('=>', ' => ').gsub('}', ' }')
16
+ else
17
+ ap(data_structure, { indent: -2, index: false, multiline: true, plain: true })
18
+ end
19
+ puts ''
20
+ end
21
+
22
+ def evaluate_data_structure_access_input
23
+ enter_evaluation_loop do |user_input|
24
+ begin
25
+ # provides the evaluation scope with variable assignment necessary for answer eval
26
+ evaluation_scope.eval("#{variable_name} = #{data_structure.to_s}")
27
+ if evaluation_scope.eval(user_input) == answer_value && user_input.include?(variable_name)
28
+ # this last returned value of 'true' within the block is vital;
29
+ # within the enter_evaluation_loop method, the return value of yield is used
30
+ true
31
+ else
32
+ puts "Remember, #{hint} Try again.\n".red
33
+ end
34
+ rescue NameError => e
35
+ print_colorized_error_prompt(e)
36
+ rescue TypeError => e
37
+ print_colorized_type_error_prompt(e)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ require_relative './question'
2
+
3
+ class DataStructureQuestion < Question
4
+ attr_accessor :data_structure, :hint, :possible_assignments
5
+
6
+ def initialize(eval_scope)
7
+ super(eval_scope)
8
+ @data_structure = data[:data_structure].clone
9
+ if data_structure.class == Array
10
+ # randomizes and shuffles the items in the arrays, so repeats remain interesting
11
+ self.data_structure = data_structure.shuffle
12
+ self.hint = 'index values start at 0.'
13
+ else
14
+ convert_keys_to_strings if [0,1,2,3,4].sample.odd?
15
+ self.hint = 'you have to use the EXACT hash key to retrieve the associated value.'
16
+ end
17
+ self.possible_assignments = []
18
+ end
19
+
20
+ def convert_keys_to_strings
21
+ altered_ds = data_structure.each_with_object({}) do |key_value_array, new_hash|
22
+ old_key = key_value_array[0]
23
+ value = key_value_array[1]
24
+ new_hash[old_key.to_s] = value
25
+ end
26
+ self.data_structure = altered_ds
27
+ end
28
+
29
+ def cull_hash_to_valid_size_for_output
30
+ desired_hash_size = rand(2..4)
31
+ while data_structure.size > desired_hash_size
32
+ key_to_delete = data_structure.keys.sample
33
+ value_deleted = data_structure.delete(key_to_delete)
34
+ new_assignment_possibility = { key_to_delete => value_deleted }
35
+ possible_assignments.push(new_assignment_possibility)
36
+ end
37
+ end
38
+
39
+ def find_number_of_boolean_values_in_hash
40
+ data_structure.select { |key, value| value.to_s.match(/true|false/i) }.size
41
+ end
42
+
43
+ end
@@ -0,0 +1,44 @@
1
+ class Question
2
+ attr_reader :type, :data
3
+ attr_accessor :variable_name, :variable_value, :data_structure,
4
+ :data_structure_class, :answer_value, :explanation,
5
+ :evaluation_scope
6
+
7
+ def initialize(evaluation_scope)
8
+ @evaluation_scope = evaluation_scope
9
+ @data = self.class.generate_question
10
+ @variable_name = rotate_array(data[:possible_variable_names]).first
11
+ end
12
+
13
+ # retrieves question from front of the array and rotates it to the back
14
+ # to avoid immediate re-sampling of questions
15
+ def self.generate_question
16
+ # calls upon *class instance* variable assigned in the subclasses
17
+ question = @questions.shift
18
+ @questions.push(question)
19
+ question
20
+ end
21
+
22
+ def enter_evaluation_loop(&block)
23
+ answered_correctly = false
24
+ until answered_correctly
25
+ begin
26
+ user_input = Readline.readline('> '.blue, true)
27
+ abort('Goodbye!'.green) if user_input.match(/^(q|exit|!!!\s?)\z/i)
28
+ if (naughty_input?(user_input) == false) && yield(user_input)
29
+ print_congratulation
30
+ sleep 1.6
31
+ clear_display
32
+ answered_correctly = true
33
+ end
34
+ rescue SyntaxError => e
35
+ if e.message.match /unexpected end-of-input/
36
+ print_unexpected_end_of_input_explanation
37
+ elsif e.message.include?('unterminated string meets end of file')
38
+ puts 'Blurg! You neglected to provide closing quotes for your string. Try again!'.red
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ end # Question
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Vander Hoop
@@ -64,12 +64,16 @@ files:
64
64
  - lib/battleroom/data/hash_questions.rb
65
65
  - lib/battleroom/data/nested_data_structure_access_questions.rb
66
66
  - lib/battleroom/data/variable_assignment_questions.rb
67
+ - lib/battleroom/data_generation_machinery.rb
67
68
  - lib/battleroom/models/array_access_question.rb
68
69
  - lib/battleroom/models/array_assignment_question.rb
70
+ - lib/battleroom/models/data_structure_access_question.rb
69
71
  - lib/battleroom/models/data_structure_assignment_question.rb
72
+ - lib/battleroom/models/data_structure_question.rb
70
73
  - lib/battleroom/models/hash_access_question.rb
71
74
  - lib/battleroom/models/hash_assignment_question.rb
72
75
  - lib/battleroom/models/nested_data_structure_access_question.rb
76
+ - lib/battleroom/models/question.rb
73
77
  - lib/battleroom/models/variable_question.rb
74
78
  homepage: https://github.com/vanderhoop/battleroom
75
79
  licenses: