battleroom 0.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9fee9b871377dbb3a8b65dca7fc1b07ac3d0a40c
4
+ data.tar.gz: 508d0df13ac79787d17a3bebdc4d1cda16d8842c
5
+ SHA512:
6
+ metadata.gz: bf4d28869289193c2a7ed72c5967fd6fafdfbf141d7911b4627a834cea0643ee723b771cf9302f7a3aa71aab9fffacbf3b90d2e3b9aaaf52cbe02ad6e53f3484
7
+ data.tar.gz: b625c24b4faedd8ad288fd843305b9d4bbf9a56fc5f744aaf99d63fda64e71952014ee3d167e7d3cecfea7aef218a5f424ab64c77ca8f296c8cf5492dae8a4b3
data/bin/battleroom ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
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
+
@@ -0,0 +1,18 @@
1
+ module BattleroomMachinery
2
+
3
+ def clear_display
4
+ `reset`
5
+ end
6
+
7
+ def random_congratulation
8
+ ["Lovely work, my friend!\n", "Beautiful!\n", "Lovely!\n", "Splendid!\n", "Nice job! Keep it rolling!\n", "Capital work, battlestar!\n", "You're on your way!\n", "Exemplary work!\n", "Yeah!\n", "Roll on.\n", "You're making a prosperous go of this programming thing.\n", "Bullseye!\n"].sample
9
+ end
10
+
11
+ def print_prompt_with_options
12
+ puts "What would you like to work on?".blue
13
+ puts "1. Variable assignment"
14
+ puts "2. Accessing values from arrays/hashes"
15
+ puts "Q. Quit\r\n\n"
16
+ end
17
+
18
+ end
@@ -0,0 +1,82 @@
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
+ ]
@@ -0,0 +1,47 @@
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
+ ]
data/lib/battleroom.rb ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'battleroom/question_data/variable_assignment'
4
+ require_relative 'battleroom/question_data/data_structure_access'
5
+ require_relative 'battleroom/battleroom_machinery'
6
+ include BattleroomMachinery
7
+ require 'colorize'
8
+ require 'pry'
9
+
10
+ clear_display
11
+ print "Welcome to the Battleroom.".blue
12
+ while true
13
+ print_prompt_with_options
14
+ choice = gets.chomp.downcase
15
+ clear_display
16
+
17
+ # for eval
18
+ b = binding
19
+
20
+ case choice
21
+ when "1"
22
+ 10.times do
23
+ question = VARIABLE_QUESTIONS.sample
24
+ var_name = question[:var_name].sample
25
+ var_value = question[:var_value].sample
26
+ puts "Create a variable, #{var_name}, and assign it the #{question[:value_type]} value #{var_value}".blue
27
+ answered_correctly = false
28
+ until answered_correctly
29
+ answer = gets.chomp
30
+ begin
31
+ b.eval(answer)
32
+ if b.eval("#{var_name} == #{var_value}")
33
+ answered_correctly = true
34
+ puts random_congratulation.green
35
+ else
36
+ print "You mis-assigned #{var_name}. ".red + "Try Again!\n".green
37
+ end
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
46
+ end
47
+ when "2"
48
+ 5.times do
49
+ question = DATA_STRUCTURE_QUESTIONS.sample
50
+ data_structure = question[:data_structure]
51
+ if data_structure.class == Array
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
82
+ end
83
+ when "q"
84
+ puts "Goodbye!".green
85
+ break
86
+ else
87
+ puts "You entered a non-option. Try again.".red
88
+ end
89
+ end
90
+
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: battleroom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Travis Vander Hoop
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-04-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Battleroom
14
+ email: vanderhoop@me.com
15
+ executables:
16
+ - battleroom
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/battleroom
21
+ - lib/battleroom.rb
22
+ - lib/battleroom/battleroom_machinery.rb
23
+ - lib/battleroom/question_data/data_structure_access.rb
24
+ - lib/battleroom/question_data/variable_assignment.rb
25
+ homepage: https://github.com/vanderhoop/battleroom
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.2.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: A simple command-line REPL designed to give Ruby newbies countless reps doing
49
+ simple tasks like assigning variables and accessing and assigning values within
50
+ nested data structures.
51
+ test_files: []