Class: CustomerRequest
- Inherits:
-
Object
- Object
- CustomerRequest
- Defined in:
- lib/customer_request.rb
Constant Summary collapse
- @@all_customers =
Parse JSON file into array
JSON.parse(customer_file)
- @@customer_responses =
JSON.parse(response_file)
- @@customer_names =
Collect customer names (array of strings) and number of customers and customer recipe names request (array of strings) and customer ingredient changes (array of hashes) and customer requests text (array of strings) and customer preferences text (array of strings)
[]
- @@no_of_customer =
@@customer_names.length
- @@customer_recipe_names =
[]
- @@customer_ingredient_changes =
[]
- @@customer_requests_text =
[]
- @@customer_preferences_text =
[]
- @@responses =
Collect customer responses (array of arrays of hashes)
[]
Class Method Summary collapse
Instance Method Summary collapse
- #display_request(customer_no) ⇒ Object
- #display_response(customer_no, mood) ⇒ Object
- #get_request(customer_no) ⇒ Object
-
#initialize ⇒ CustomerRequest
constructor
A new instance of CustomerRequest.
Constructor Details
#initialize ⇒ CustomerRequest
67 68 |
# File 'lib/customer_request.rb', line 67 def initialize end |
Class Method Details
.no_of_customer ⇒ Object
70 71 72 |
# File 'lib/customer_request.rb', line 70 def self.no_of_customer @@no_of_customer end |
Instance Method Details
#display_request(customer_no) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/customer_request.rb', line 98 def display_request(customer_no) # Initialise frame for output formatting dialog_box = ScreenMessage.new customer_name = @@customer_names[customer_no] customer_request_text = @@customer_requests_text[customer_no] customer_preference_text = @@customer_preferences_text[customer_no] # Put all string output lines in a variable msg = "" msg += customer_request_text msg += "\n" msg += customer_preference_text # Format output using frame dialog_box.msg_frame(customer_name, msg) end |
#display_response(customer_no, mood) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/customer_request.rb', line 115 def display_response(customer_no, mood) # Initialise frame for output formatting dialog_box = ScreenMessage.new customer_name = @@customer_names[customer_no] customer_response = @@responses[customer_no] # Put all string output lines in a variable msg = "" customer_response.each do |response| response.each do |type, text| msg += text if mood === type end end # Format output using frame dialog_box.msg_frame(customer_name, msg) end |
#get_request(customer_no) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/customer_request.rb', line 74 def get_request(customer_no) # Get all original recipes for base recipes (array of hashes) base_recipes = Recipe.all_recipes # Create customer recipe based on preference (array of hashes) customer_recipe = [] requested_recipe_name = @@customer_recipe_names[customer_no] requested_ingredient = @@customer_ingredient_changes[customer_no] base_recipes.each do |recipe| if recipe.key?(requested_recipe_name) customer_recipe = recipe[requested_recipe_name].dup # => Not yet changed # Change here customer_recipe.each_with_index do |list, i| if list.keys === requested_ingredient.keys customer_recipe[i] = requested_ingredient end end end end # Array of ingredient-quantity hashes customer_recipe end |