-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhash-and-method-example.rb
166 lines (145 loc) · 5.83 KB
/
hash-and-method-example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Static Database
online_orders = {
'order_abc1' => {
item_number: 'it0001',
order_date: '2020-02-10',
order_status: 'arrived',
order_arrival_date: '2020-02-12',
order_tracking_info: '390344839629',
order_associated_customer: 'cid_001'},
'order_abc2' => {
item_number: 'it0005',
order_date: '2020-02-15',
order_status: 'shipping',
order_arrival_date: '2020-02-15',
order_tracking_info: 'pending',
order_associated_customer: 'cid_002'},
'order_abc3' => {
item_number: 'it0025',
order_date: '2020-02-16',
order_status: 'pending credit',
order_arrival_date: 'pending',
order_tracking_info: 'pending',
order_associated_customer: 'cid_002'},
}
# Debugging
# puts online_orders["order_abc1"].keys
# puts online_orders["order_abc1"][:order_associated_customer]
account_rep = {
'ar_001' => {
ar_first_name: 'James',
ar_last_name: 'Hobo',
ar_company_title: 'Development',
ar_contact_phone_1: '222-222-2222',
ar_contact_phone_2: '0',
ar_contact_email_1: 'hobo@italicwebs.com'},
'ar_002' => {
ar_first_name: 'Jose',
ar_last_name: 'Polar',
ar_company_title: 'Development',
ar_contact_phone_1: '333-333-3333',
ar_contact_phone_2: '0',
ar_contact_email_1: 'jose.polar@italicwebs.com'},
}
# Debugging
# puts account_rep["ar_001"]
# puts account_rep["ar_002"][:ar_last_name]
customer_information = {
'cid_001' => {
cus_first_name: 'John',
cus_middle_name: 'P.',
cus_last_name: 'Doe',
cus_address_street_1: 'P.O Box 1001',
cus_address_street_2: 'Att: John',
cus_address_city: 'Fresno',
cus_address_state: 'CA',
cus_address_zip: '93702',
cus_address_country: 'United States',
cus_account_rep: account_rep["ar_001"]},
'cid_002' => {
cus_first_name: 'Jane',
cus_middle_name: 'P.',
cus_last_name: 'Doe',
cus_address_street_1: 'P.O Box 1002',
cus_address_street_2: 'Att: Jane',
cus_address_city: 'Clovis',
cus_address_state: 'CA',
cus_address_zip: '93702',
cus_address_country: 'United States',
cus_account_rep: account_rep["ar_002"]},
}
# Methods
def start_order_tracking(online_orders:, account_rep:, customer_information:)
system "clear" # Ruby standard but doesn't work in Windows Interactive
system('cls') # Works in Windows Inactive
puts "-- Welcome to our order tracker --"
puts "Please enter your order number below for us to look up"
puts query_order_number = gets.chomp
if (online_orders).keys.include?(query_order_number)
puts "Checking Your Order. Please wait"
else
puts "[ERROR] Could not locate your order! Press enter to try again."
gets
start_order_tracking(online_orders: online_orders, account_rep: account_rep, customer_information: customer_information,)
end
system "clear" # Ruby standard but doesn't work in Windows Interactive
system('cls') # Works in Windows Inactive
# Pulls the customer ID from the order. This could be eliminated as we could reference the array for information.
resulting_customer_id = online_orders[query_order_number][:order_associated_customer]
# Pulls the complete array for the computer customer ID
resulting_customer_array = customer_information[resulting_customer_id]
# Pulls the customer's Account representative
resulting_account_rep = customer_information[resulting_customer_id][:cus_account_rep]
# Welcomes the customer by their first name
puts "Hello #{resulting_customer_array[:cus_first_name]}!"
# Debugging
# puts online_orders[query_order_number][:order_status] == "arrived"
# Outputs order, it's current status and any action the customer should take
if online_orders[query_order_number][:order_status] == "arrived"
status_order_arrived(
ar_first_name: resulting_account_rep[:ar_first_name],
ar_last_name: resulting_account_rep[:ar_last_name],
ar_contact_phone: resulting_account_rep[:ar_contact_phone_1],
ar_contact_email: resulting_account_rep[:ar_contact_email_1],
)
elsif online_orders[query_order_number][:order_status] == "shipping"
status_order_shipping
elsif online_orders[query_order_number][:order_status] == "pending credit"
system "clear"
status_order_pending_credit(
ar_first_name: resulting_account_rep[:ar_first_name],
ar_last_name: resulting_account_rep[:ar_last_name],
ar_contact_phone: resulting_account_rep[:ar_contact_phone_1],
ar_contact_email: resulting_account_rep[:ar_contact_email_1],
)
else
status_order_pending_credit(
ar_first_name: resulting_account_rep[:ar_first_name],
ar_last_name: resulting_account_rep[:ar_last_name],
ar_contact_phone: resulting_account_rep[:ar_contact_phone_1],
ar_contact_email: resulting_account_rep[:ar_contact_email_1],
)
end
end
def status_order_arrived(ar_first_name:, ar_last_name:, ar_contact_phone:, ar_contact_email:)
puts "Our tracking shows your package has arrived! If this is an error, please contact your representative using the information below:"
puts "#{ar_first_name} #{ar_last_name}"
puts "Over the phone: #{ar_contact_phone}"
puts "Over email: #{ar_contact_email}"
end
def status_order_shipping
puts "We're working on getting your package shipped out. We'll get back to you soon!"
end
def status_order_pending_credit(ar_first_name:, ar_last_name:, ar_contact_phone:, ar_contact_email:)
puts "We're processing credit on your package. If this does not clear, please contact your representative using the information below:"
puts "#{ar_first_name} #{ar_last_name}"
puts "Over the phone: #{ar_contact_phone}"
puts "Over email: #{ar_contact_email}"
end
def status_order_error(ar_first_name:, ar_last_name:, ar_contact_phone:, ar_contact_email:)
puts "Could not locate a status. For an update, please contact your representative using the information below:"
puts "#{ar_first_name} #{ar_last_name}"
puts "Over the phone: #{ar_contact_phone}"
puts "Over email: #{ar_contact_email}"
end
start_order_tracking(online_orders: online_orders, account_rep: account_rep, customer_information: customer_information,)