E-commerce companies receive daily exports from Shopify/Square and need automated monthly reports for management. This drill teaches you to parse sales CSV data, calculate monthly revenue by category, identify top-selling products, and generate summary reports with totals, averages, and percentage breakdowns. You'll master CSV processing with type converters, hash aggregation operations, and business metric calculations.
CSV.read(file, headers: true) gives hash-like access to columns
Date.parse(string).strftime('%Y-%m') extracts year-month
Use nested hashes: Hash.new { |h, k| h[k] = Hash.new(0) }
Calculate revenue per transaction: quantity * unit_price
Use group_by to aggregate by month or category
transform_values applies operation to all hash values
max_by finds the hash entry with maximum value
analyze_sales('sales.csv')
Total revenue: $3,300 Best month: 2024-01 ($2,900) Top category: Electronics (72.7%)
analyze_sales('sales.csv')
Total revenue: $250 Best month: 2024-03 ($250) Top category: Electronics (100.0%)
analyze_sales('sales.csv')
Total revenue: $1,800 Best month: 2024-01 ($1,800) Top category: Electronics (55.6%)
Console output will appear here...
Are you sure?
You're making great progress