Skip to content

Instantly share code, notes, and snippets.

@abutler3
Created May 27, 2016 03:57
Show Gist options
  • Save abutler3/f854777f8d3abe4edb5d9f25b7f67869 to your computer and use it in GitHub Desktop.
Save abutler3/f854777f8d3abe4edb5d9f25b7f67869 to your computer and use it in GitHub Desktop.
require 'date'
puts Date.today.to_s
puts " _ _ "
puts " | | | | "
puts " _ __ _ __ ___ __| |_ _ ___| |_ ___ "
puts "| '_ \\| '__/ _ \\ / _` | | | |/ __| __/ __|"
puts "| |_) | | | (_) | (_| | |_| | (__| |_\\__ \\"
puts "| .__/|_| \\___/ \\__,_|\\__,_|\\___|\\__|___/"
puts "| | "
puts "|_| "
# For each product in the data set:
# Print the name of the toy
# Print the retail price of the toy
# Calculate and print the total number of purchases
# Calculate and print the total amount of sales
# Calculate and print the average price the toy sold for
# Calculate and print the average discount (% or $) based off the average sales price
purchases = 0
sales_amount = 0
price_average = 0
retail_price = 0
discount = 0
discount_percentage = 0
products_hash["items"].each do |toy|
puts "Name of Toy: #{toy['title']}"
retail_price = toy['full-price']
puts "Retail Price: #{retail_price}"
purchases += toy['purchases'].count
toy['purchases'].each do |purchase|
puts individual_purchase = purchase['price']
sales_amount += purchase['price']
price_average = sales_amount / purchases
discount += retail_price.to_i - individual_purchase.to_i
puts discount
# discount = discount / purchases
# discount_percentage = discount.to_i / retail_price.to_i * 100.0
end
discount = discount.to_i / retail_price.to_i
puts "Average discount price: #{discount.to_f}"
# puts toy
end
puts "Total number of purchases: #{purchases}"
puts "Total amount of sales: #{sales_amount}"
puts "Average price sold for: #{price_average}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment