In: Computer Science
Ruby Problem
Create a template for an email letterhead with the following variables. The letter head will have format place holders for:
Company name
Street address
City, State and zip code
Telephone
Web site URL
Use the array of data below to fill your template place holders:
Run your finished script and capture the output to a file named email_template.txt.
# Two pieces of data in one array (multi dimensional array) contact_data = [ ['Company 1','123 Main Street', 'Anytown','Anystate', 88888,'444-444-4444','[email protected]','https://company1.com'], ['Company 2','77 Market Street', 'San Francisco','California', 94111,'415-444-4444','[email protected]','https://company2.com'] ] ######### CREATE YOUR EMAIL TEMPLATE HERE ######### email_template = "" # Process the data one array at a time contact_data.each do |arr| # your code goes here. end
Your output should end up looking something like this:
Company 1 123 Main Street Anytown, Anystate 88888 Tel: 444-444-4444 Email: [email protected] URL: https://company1.com ------------------------------ Company 2 77 Market Street San Francisco, California 94111 Tel: 415-444-4444 Email: [email protected] URL: https://company2.com ------------------------------
Answer
# Two pieces of data in one array (multi dimensional
array)
contact_data = [
['Company 1','123 Main Street', 'Anytown','Anystate',
88888,'444-444-4444','[email protected]','https://company1.com'],
['Company 2','77 Market Street', 'San Francisco','California',
94111,'415-444-4444','[email protected]','https://company2.com']
]
######### CREATE YOUR EMAIL TEMPLATE HERE #########
email_template = ""
# Process the data one array at a time
# Loop over each row array.
contact_data.each do |arr|
# Loop over each cell in the row.
puts arr[0]
puts arr[1]
puts arr[2]<<", "<<arr[3]<<"
"<<arr[4].to_s
puts "Tel : "<<arr[5]
puts "Email : "<<arr[6]
puts "URL : "<<arr[7]
# End of row.
puts "----------------------------"
end
OUTPUT