Challenge

Problem

Documentation is critical in software development, and markdown is the universal format for READMEs, wikis, and documentation sites. This drill teaches you to read CSV data and transform it into properly formatted markdown tables with alignment, padding, and separators. You'll learn markdown table syntax, dynamic column width calculation, string alignment techniques, and text formatting—skills essential for generating documentation, reports, and developer tools. Note: This drill parses CSV manually using string methods rather than Ruby's CSV library.

Difficulty: Beginner

Instructions

  1. Read CSV file with headers
  2. Calculate the maximum width needed for each column (including header)
  3. Generate markdown table with:
    • Header row with column names
    • Separator row with dashes (e.g., | --- | --- |)
    • Data rows with values
  4. Pad all cells to their column's maximum width
  5. Left-align text columns, right-align number columns
  6. Return the markdown table as a string
  7. Print confirmation: 'Markdown table generated: X rows, Y columns'

Files

Editable
Read-only

Hints

Hint 1

Parse CSV manually: line.split(',')

Hint 2

First row is headers, remaining rows are data

Hint 3

Calculate max width: array.map(&:length).max

Hint 4

Use map.with_index to iterate with column index

Hint 5

string.ljust(width) pads right, string.rjust(width) pads left

Hint 6

Check if numeric: string.match?(/^\d+\.?\d*$/)

Hint 7

Join array with separator: array.join(' | ')

Ruby 3.4

Provided Files (Read-only)

1. Correct confirmation message

Input:
generate_markdown_table('data.csv')
Expected Output:
Markdown table generated: 4 rows, 4 columns

2. Header row formatted correctly

Input:
md = generate_markdown_table('data.csv')
puts md.lines.first
Expected Output:
Markdown table generated: 4 rows, 4 columns
| Name  | Department  | Salary | Years |

3. Separator row has dashes

Input:
md = generate_markdown_table('data.csv')
puts md.lines[1]
Expected Output:
Markdown table generated: 4 rows, 4 columns
| ----- | ----------- | ------ | ----- |
+ 2 hidden test cases