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, dynamic column width calculation, and alignment techniques—essential for command-line tools, email reports, and system administration summaries. Note: This drill parses CSV manually using string methods rather than Ruby's CSV library.
String#ljust(width) left-aligns text with padding
String#rjust(width) right-aligns text with padding
Calculate max width: array.map { |r| r[0].length }.max
Format with commas: num.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1,').reverse
Parse CSV manually: line.split(',')
Use [calculated_width, header_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 Engineering $105,000 8 Carol Davis Sales $68,000 2 ------------------------------------------- Total employees: 4 Average salary: $85,750 Total payroll: $343,000
generate_report('employees.csv')
puts 'Formatting verified'
Name Department Salary Years ------------------------------------------- John Smith Engineering $95,000 5 Alice Johnson Marketing $75,000 3 Bob Williams Engineering $105,000 8 Carol Davis Sales $68,000 2 ------------------------------------------- Total employees: 4 Average salary: $85,750 Total payroll: $343,000 Formatting verified
generate_report('employees.csv')
puts 'Stats verified'
Name Department Salary Years ------------------------------------------- John Smith Engineering $95,000 5 Alice Johnson Marketing $75,000 3 Bob Williams Engineering $105,000 8 Carol Davis Sales $68,000 2 ------------------------------------------- Total employees: 4 Average salary: $85,750 Total payroll: $343,000 Stats verified
Console output will appear here...
Are you sure?
You're making great progress
Become a Ruby Pro
1,600+ problems to master every concept