Skip to content

Instantly share code, notes, and snippets.

@laurenkruczyk
Created March 4, 2014 03:09
Show Gist options
  • Save laurenkruczyk/9339616 to your computer and use it in GitHub Desktop.
Save laurenkruczyk/9339616 to your computer and use it in GitHub Desktop.
#INCOMPLETE
require 'pry'
require 'csv'
require_relative 'cash_3_methods'
def build_array_from_csv(filename)
inventory_array = []
CSV.foreach(filename, :headers => true) do |row|
inventory_array << row.to_hash
end
inventory_array
end
def print_menu(array)
options = [1,2,3,4,5]
puts "Welcome to James' coffee emporium!"
puts ""
puts "#{options[0]}) Add item - $#{array[0]["retail_price"]} - #{array[0]["name"]}"
puts "#{options[1]}) Add item - $#{array[1]["retail_price"]} - #{array[1]["name"]}"
puts "#{options[2]}) Add item - $#{array[2]["retail_price"]} - #{array[2]["name"]}"
puts "#{options[3]}) Complete Sale"
end
def prompt(string)
puts string
gets.chomp
end
def make_line_item(user_selection, quantity)
{ user_selection => quantity.to_i }
end
# Until user inputs done (4)
#Take user input for selection
#Take user input for quantity
#Keep building a receipt
def process_sale(sale)
user_selection = prompt('What is your selection?')
if user_selection != "4"
quantity = prompt('How many bags?')
line_item = make_line_item(user_selection, quantity)
sale << line_item
#output subtotal
process_sale(sale)
else
puts "maybe?"
end
end
sale = []
menu_array = build_array_from_csv('products.csv')
print_menu(menu_array)
process_sale(sale)
# outputting total and receipt to screen
# write receipt to file
binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment