When stakeholders prefer plain text over CSV, proper formatting makes data comprehensible. This drill teaches you to transform data into human-readable text reports with aligned columns, proper spacing, and summary statistics. You'll learn string formatting with printf, dynamic column width calculation, and alignment techniques—essential for command-line tools, email reports, and system administration summaries.
String#ljust(width) left-aligns text with padding
String#rjust(width) right-aligns text with padding
Calculate max width: array.map(&:length).max
Format with commas: number.to_s.reverse.scan(/\d{1,3}/).join(',').reverse
CSV.read(file, headers: true) gives you hash-like access
Use [calculated_width, minimum_width].max for column widths
generate_report('employees.csv')
Name Department Salary Years --------------------------------------------- John Smith Engineering $95,000 5 Alice Johnson Marketing $75,000 3 Bob Williams Sales $68,000 2 --------------------------------------------- Total employees: 3 Average salary: $79,333 Total payroll: $238,000
generate_report('employees.csv')
Name Department Salary Years ------------------------------------- Jane Doe HR $55,000 1 ------------------------------------- Total employees: 1 Average salary: $55,000 Total payroll: $55,000
generate_report('employees.csv')
Name Department Salary Years ----------------------------------------- Sarah Lee Executive $250,000 15 Mike Chen Engineering $125,000 7 ----------------------------------------- Total employees: 2 Average salary: $187,500 Total payroll: $375,000
Console output will appear here...
Are you sure?
You're making great progress