burger_game 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,172 +1,172 @@
1
- [
2
- {
3
- " A Customer ":
4
- [
5
- {
6
- "Normal Burger":
7
- [
8
- {"Cheese": 0}
9
- ]
10
- },
11
- {
12
- "Request": "Hello! Can I please have a \"Normal Burger\" today?"
13
- },
14
- {
15
- "Preference": "I don't like cheese, so, with no cheese please!"
16
- }
17
- ]
18
- },
19
- {
20
- " Captain Australia ":
21
- [
22
- {
23
- "Questionable Burger":
24
- [
25
- {"Grilled Chicken": 5}
26
- ]
27
- },
28
- {
29
- "Request": "G'day mate! Can I get \"Questionable Burger\" please?"
30
- },
31
- {
32
- "Preference": "I'm so hungry, please put an extra patty in my burger! Ta!"
33
- }
34
- ]
35
- },
36
- {
37
- " John Citizen ":
38
- [
39
- {
40
- "Healthy Burger":
41
- [
42
- {"Lettuce": 0}
43
- ]
44
- },
45
- {
46
- "Request": "Hi there. I'm a healthy person you know.\nSo, can I have \"Healthy Burger\" please?"
47
- },
48
- {
49
- "Preference": "And, with no veggies please. Yes, you heard me right, no veggies!"
50
- }
51
- ]
52
- },
53
- {
54
- " Jane Citizen ":
55
- [
56
- {
57
- "Healthy Burger":
58
- [
59
- {"Grilled Chicken": 0}
60
- ]
61
- },
62
- {
63
- "Request": "Hi... I'd like to have the \"Healthy Burger\" please."
64
- },
65
- {
66
- "Preference": "I don't want the chicken. It reminds me of John..."
67
- }
68
- ]
69
- },
70
- {
71
- " Scott Morris ":
72
- [
73
- {
74
- "Questionable Burger":
75
- [
76
- {"Cheese": 5}
77
- ]
78
- },
79
- {
80
- "Request": "Good day! A quick question, can I have the \"Questionable Burger\" please?"
81
- },
82
- {
83
- "Preference": "With extra two slices of cheese please.\nI hope it is not cheesy. Hahaha! *laughs at own attempt to be funny*"
84
- }
85
- ]
86
- },
87
- {
88
- " The Mighty Princess ":
89
- [
90
- {
91
- "Healthy Burger":
92
- [
93
- {"Lettuce": 4}
94
- ]
95
- },
96
- {
97
- "Request": "Oh, tell me dear citizen, can this Princess have the \"Healthy Burger\" please?"
98
- },
99
- {
100
- "Preference": "Make it with extra one lettuce! I will reward you handsomely..."
101
- }
102
- ]
103
- },
104
- {
105
- " Donald T. ":
106
- [
107
- {
108
- "Questionable Burger":
109
- [
110
- {"Lettuce": 0}
111
- ]
112
- },
113
- {
114
- "Request": "I'm a busy man. Give the \"Questionable Burger\". Thanks."
115
- },
116
- {
117
- "Preference": "Oh, and I'll have it without lettuce!\nNo lettuce!! *throws fist in the air*"
118
- }
119
- ]
120
- },
121
- {
122
- " Mickey M. ":
123
- [
124
- {
125
- "Healthy Burger":
126
- [
127
- {"Tomato Sauce": 2}
128
- ]
129
- },
130
- {
131
- "Request": "Hello... Hmm... I'm interested in trying the \"Healthy Burger\" please..."
132
- },
133
- {
134
- "Preference": "I love tomato, so can I have double the sauce please?"
135
- }
136
- ]
137
- },
138
- {
139
- " Unicorn ":
140
- [
141
- {
142
- "Questionable Burger":
143
- [
144
- {"Tomato Sauce": 0}
145
- ]
146
- },
147
- {
148
- "Request": "Hiya! Can I have \"Questionable Burger\" please?"
149
- },
150
- {
151
- "Preference": "Leave the tomato sauce out please.\nIt will ruin the colour balance of my rainbow."
152
- }
153
- ]
154
- },
155
- {
156
- " A Robot ":
157
- [
158
- {
159
- "Normal Burger":
160
- [
161
- {"Grilled Chicken": 3}
162
- ]
163
- },
164
- {
165
- "Request": "Beep... Can I have the.. Beep... \"Normal Burger\" please?"
166
- },
167
- {
168
- "Preference": "Beep... With triple... Beep... Patty please..."
169
- }
170
- ]
171
- }
1
+ [
2
+ {
3
+ " A Customer ":
4
+ [
5
+ {
6
+ "Normal Burger":
7
+ [
8
+ {"Cheese": 0}
9
+ ]
10
+ },
11
+ {
12
+ "Request": "Hello! Can I please have a \"Normal Burger\" today?"
13
+ },
14
+ {
15
+ "Preference": "I don't like cheese, so, with no cheese please!"
16
+ }
17
+ ]
18
+ },
19
+ {
20
+ " Captain Australia ":
21
+ [
22
+ {
23
+ "Questionable Burger":
24
+ [
25
+ {"Grilled Chicken": 5}
26
+ ]
27
+ },
28
+ {
29
+ "Request": "G'day mate! Can I get \"Questionable Burger\" please?"
30
+ },
31
+ {
32
+ "Preference": "I'm so hungry, please put an extra patty in my burger! Ta!"
33
+ }
34
+ ]
35
+ },
36
+ {
37
+ " John Citizen ":
38
+ [
39
+ {
40
+ "Healthy Burger":
41
+ [
42
+ {"Lettuce": 0}
43
+ ]
44
+ },
45
+ {
46
+ "Request": "Hi there. I'm a healthy person you know.\nSo, can I have \"Healthy Burger\" please?"
47
+ },
48
+ {
49
+ "Preference": "And, with no veggies please. Yes, you heard me right, no veggies!"
50
+ }
51
+ ]
52
+ },
53
+ {
54
+ " Jane Citizen ":
55
+ [
56
+ {
57
+ "Healthy Burger":
58
+ [
59
+ {"Grilled Chicken": 0}
60
+ ]
61
+ },
62
+ {
63
+ "Request": "Hi... I'd like to have the \"Healthy Burger\" please."
64
+ },
65
+ {
66
+ "Preference": "I don't want the chicken. It reminds me of John..."
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ " Scott Morris ":
72
+ [
73
+ {
74
+ "Questionable Burger":
75
+ [
76
+ {"Cheese": 5}
77
+ ]
78
+ },
79
+ {
80
+ "Request": "Good day! A quick question, can I have the \"Questionable Burger\" please?"
81
+ },
82
+ {
83
+ "Preference": "With extra two slices of cheese please.\nI hope it is not cheesy. Hahaha! *laughs at own attempt to be funny*"
84
+ }
85
+ ]
86
+ },
87
+ {
88
+ " The Mighty Princess ":
89
+ [
90
+ {
91
+ "Healthy Burger":
92
+ [
93
+ {"Lettuce": 4}
94
+ ]
95
+ },
96
+ {
97
+ "Request": "Oh, tell me dear citizen, can this Princess have the \"Healthy Burger\" please?"
98
+ },
99
+ {
100
+ "Preference": "Make it with extra one lettuce! I will reward you handsomely..."
101
+ }
102
+ ]
103
+ },
104
+ {
105
+ " Donald T. ":
106
+ [
107
+ {
108
+ "Questionable Burger":
109
+ [
110
+ {"Lettuce": 0}
111
+ ]
112
+ },
113
+ {
114
+ "Request": "I'm a busy man. Give the \"Questionable Burger\". Thanks."
115
+ },
116
+ {
117
+ "Preference": "Oh, and I'll have it without lettuce!\nNo lettuce!! *throws fist in the air*"
118
+ }
119
+ ]
120
+ },
121
+ {
122
+ " Mickey M. ":
123
+ [
124
+ {
125
+ "Healthy Burger":
126
+ [
127
+ {"Tomato Sauce": 2}
128
+ ]
129
+ },
130
+ {
131
+ "Request": "Hello... Hmm... I'm interested in trying the \"Healthy Burger\" please..."
132
+ },
133
+ {
134
+ "Preference": "I love tomato, so can I have double the sauce please?"
135
+ }
136
+ ]
137
+ },
138
+ {
139
+ " Unicorn ":
140
+ [
141
+ {
142
+ "Questionable Burger":
143
+ [
144
+ {"Tomato Sauce": 0}
145
+ ]
146
+ },
147
+ {
148
+ "Request": "Hiya! Can I have \"Questionable Burger\" please?"
149
+ },
150
+ {
151
+ "Preference": "Leave the tomato sauce out please.\nIt will ruin the colour balance of my rainbow."
152
+ }
153
+ ]
154
+ },
155
+ {
156
+ " A Robot ":
157
+ [
158
+ {
159
+ "Normal Burger":
160
+ [
161
+ {"Grilled Chicken": 3}
162
+ ]
163
+ },
164
+ {
165
+ "Request": "Beep... Can I have the.. Beep... \"Normal Burger\" please?"
166
+ },
167
+ {
168
+ "Preference": "Beep... With triple... Beep... Patty please..."
169
+ }
170
+ ]
171
+ }
172
172
  ]
@@ -1,132 +1,132 @@
1
- require_relative './recipe'
2
- require_relative './screen_message'
3
-
4
- class CustomerRequest
5
- # ERROR HANDLING for reading files
6
- begin
7
- # Read customer_request.JSON file
8
- customer_file = File.read(File.join(File.dirname(__FILE__), './customer_request.json'))
9
-
10
- rescue Errno::ENOENT => e
11
- puts "Could not find customer_request.json file. Please put customer_request.json in the 'data' directory."
12
- puts e.message
13
- exit
14
- rescue => e
15
- puts "Something went wrong."
16
- puts "Error message: " + e.message
17
- exit
18
- end
19
-
20
- begin
21
- # Read customer_response.JSON file
22
- response_file = File.read(File.join(File.dirname(__FILE__), './customer_response.json'))
23
-
24
- rescue Errno::ENOENT => e
25
- puts "Could not find customer_response.json file. Please put customer_response.json in the 'data' directory."
26
- puts e.message
27
- exit
28
- rescue => e
29
- puts "Something went wrong."
30
- puts "Error message: " + e.message
31
- exit
32
- end
33
-
34
- # Parse JSON file into array
35
- @@all_customers = JSON.parse(customer_file)
36
- @@customer_responses = JSON.parse(response_file)
37
-
38
- # Collect customer names (array of strings)
39
- # and number of customers
40
- # and customer recipe names request (array of strings)
41
- # and customer ingredient changes (array of hashes)
42
- # and customer requests text (array of strings)
43
- # and customer preferences text (array of strings)
44
- @@customer_names = []
45
- @@no_of_customer = 0
46
- @@customer_recipe_names = []
47
- @@customer_ingredient_changes = []
48
- @@customer_requests_text = []
49
- @@customer_preferences_text = []
50
- @@all_customers.each do |customer|
51
- customer.each do |name, request|
52
- @@customer_names << name
53
- @@customer_recipe_names << request[0].keys[0]
54
- @@customer_ingredient_changes << request[0].values[0][0]
55
- @@customer_requests_text << request[1].values.join
56
- @@customer_preferences_text << request[2].values.join
57
- end
58
- end
59
- @@no_of_customer = @@customer_names.length
60
-
61
- # Collect customer responses (array of arrays of hashes)
62
- @@responses = []
63
- @@customer_responses.each do |responses|
64
- @@responses << responses.values
65
- end
66
-
67
- def initialize
68
- end
69
-
70
- def self.no_of_customer
71
- @@no_of_customer
72
- end
73
-
74
- def get_request(customer_no)
75
- # Get all original recipes for base recipes (array of hashes)
76
- base_recipes = Recipe.all_recipes
77
-
78
- # Create customer recipe based on preference (array of hashes)
79
- customer_recipe = []
80
- requested_recipe_name = @@customer_recipe_names[customer_no]
81
- requested_ingredient = @@customer_ingredient_changes[customer_no]
82
- base_recipes.each do |recipe|
83
- if recipe.key?(requested_recipe_name)
84
- customer_recipe = recipe[requested_recipe_name].dup # => Not yet changed
85
- # Change here
86
- customer_recipe.each_with_index do |list, i|
87
- if list.keys === requested_ingredient.keys
88
- customer_recipe[i] = requested_ingredient
89
- end
90
- end
91
- end
92
- end
93
-
94
- # Array of ingredient-quantity hashes
95
- customer_recipe
96
- end
97
-
98
- def display_request(customer_no)
99
- # Initialise frame for output formatting
100
- dialog_box = ScreenMessage.new
101
- customer_name = @@customer_names[customer_no]
102
- customer_request_text = @@customer_requests_text[customer_no]
103
- customer_preference_text = @@customer_preferences_text[customer_no]
104
-
105
- # Put all string output lines in a variable
106
- msg = ""
107
- msg += customer_request_text
108
- msg += "\n"
109
- msg += customer_preference_text
110
-
111
- # Format output using frame
112
- dialog_box.msg_frame(customer_name, msg)
113
- end
114
-
115
- def display_response(customer_no, mood)
116
- # Initialise frame for output formatting
117
- dialog_box = ScreenMessage.new
118
- customer_name = @@customer_names[customer_no]
119
- customer_response = @@responses[customer_no]
120
-
121
- # Put all string output lines in a variable
122
- msg = ""
123
- customer_response.each do |response|
124
- response.each do |type, text|
125
- msg += text if mood === type
126
- end
127
- end
128
-
129
- # Format output using frame
130
- dialog_box.msg_frame(customer_name, msg)
131
- end
1
+ require_relative './recipe'
2
+ require_relative './screen_message'
3
+
4
+ class CustomerRequest
5
+ # ERROR HANDLING for reading files
6
+ begin
7
+ # Read customer_request.JSON file
8
+ customer_file = File.read(File.join(File.dirname(__FILE__), './customer_request.json'))
9
+
10
+ rescue Errno::ENOENT => e
11
+ puts "Could not find customer_request.json file. Please put customer_request.json in the 'data' directory."
12
+ puts e.message
13
+ exit
14
+ rescue => e
15
+ puts "Something went wrong."
16
+ puts "Error message: " + e.message
17
+ exit
18
+ end
19
+
20
+ begin
21
+ # Read customer_response.JSON file
22
+ response_file = File.read(File.join(File.dirname(__FILE__), './customer_response.json'))
23
+
24
+ rescue Errno::ENOENT => e
25
+ puts "Could not find customer_response.json file. Please put customer_response.json in the 'data' directory."
26
+ puts e.message
27
+ exit
28
+ rescue => e
29
+ puts "Something went wrong."
30
+ puts "Error message: " + e.message
31
+ exit
32
+ end
33
+
34
+ # Parse JSON file into array
35
+ @@all_customers = JSON.parse(customer_file)
36
+ @@customer_responses = JSON.parse(response_file)
37
+
38
+ # Collect customer names (array of strings)
39
+ # and number of customers
40
+ # and customer recipe names request (array of strings)
41
+ # and customer ingredient changes (array of hashes)
42
+ # and customer requests text (array of strings)
43
+ # and customer preferences text (array of strings)
44
+ @@customer_names = []
45
+ @@no_of_customer = 0
46
+ @@customer_recipe_names = []
47
+ @@customer_ingredient_changes = []
48
+ @@customer_requests_text = []
49
+ @@customer_preferences_text = []
50
+ @@all_customers.each do |customer|
51
+ customer.each do |name, request|
52
+ @@customer_names << name
53
+ @@customer_recipe_names << request[0].keys[0]
54
+ @@customer_ingredient_changes << request[0].values[0][0]
55
+ @@customer_requests_text << request[1].values.join
56
+ @@customer_preferences_text << request[2].values.join
57
+ end
58
+ end
59
+ @@no_of_customer = @@customer_names.length
60
+
61
+ # Collect customer responses (array of arrays of hashes)
62
+ @@responses = []
63
+ @@customer_responses.each do |responses|
64
+ @@responses << responses.values
65
+ end
66
+
67
+ def initialize
68
+ end
69
+
70
+ def self.no_of_customer
71
+ @@no_of_customer
72
+ end
73
+
74
+ def get_request(customer_no)
75
+ # Get all original recipes for base recipes (array of hashes)
76
+ base_recipes = Recipe.all_recipes
77
+
78
+ # Create customer recipe based on preference (array of hashes)
79
+ customer_recipe = []
80
+ requested_recipe_name = @@customer_recipe_names[customer_no]
81
+ requested_ingredient = @@customer_ingredient_changes[customer_no]
82
+ base_recipes.each do |recipe|
83
+ if recipe.key?(requested_recipe_name)
84
+ customer_recipe = recipe[requested_recipe_name].dup # => Not yet changed
85
+ # Change here
86
+ customer_recipe.each_with_index do |list, i|
87
+ if list.keys === requested_ingredient.keys
88
+ customer_recipe[i] = requested_ingredient
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ # Array of ingredient-quantity hashes
95
+ customer_recipe
96
+ end
97
+
98
+ def display_request(customer_no)
99
+ # Initialise frame for output formatting
100
+ dialog_box = ScreenMessage.new
101
+ customer_name = @@customer_names[customer_no]
102
+ customer_request_text = @@customer_requests_text[customer_no]
103
+ customer_preference_text = @@customer_preferences_text[customer_no]
104
+
105
+ # Put all string output lines in a variable
106
+ msg = ""
107
+ msg += customer_request_text
108
+ msg += "\n"
109
+ msg += customer_preference_text
110
+
111
+ # Format output using frame
112
+ dialog_box.msg_frame(customer_name, msg)
113
+ end
114
+
115
+ def display_response(customer_no, mood)
116
+ # Initialise frame for output formatting
117
+ dialog_box = ScreenMessage.new
118
+ customer_name = @@customer_names[customer_no]
119
+ customer_response = @@responses[customer_no]
120
+
121
+ # Put all string output lines in a variable
122
+ msg = ""
123
+ customer_response.each do |response|
124
+ response.each do |type, text|
125
+ msg += text if mood === type
126
+ end
127
+ end
128
+
129
+ # Format output using frame
130
+ dialog_box.msg_frame(customer_name, msg)
131
+ end
132
132
  end