Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

RubybeginnercliAI generated

Markdown Table Formatter CLI

Build a Ruby command-line tool that turns comma- or tab-separated data into a neatly aligned Markdown table, perfect for pasting into a README or documentation. Pipe data in or give it a file, and it works out each column's width, pads every cell, builds the header separator (with optional left, center or right alignment per column), and escapes characters that would break the table, such as |. It uses only Ruby's standard library. It's a great first Ruby project: you'll learn reading files and standard input, splitting and processing text, arrays and their methods (map, zip and max), string formatting, the csv library, and OptionParser.

Estimate
~5h
Steps
5
Completed by
0
Proposed by
codeseed.app

Standard Library

Project roadmap

  1. 01

    Read the input

    ~1h

    Write mdtable.rb that reads from a file given as an argument, or from standard input when none is given (ARGF does both). Parse it with the csv library using the delimiter from --delimiter (comma by default, or tab with --tsv), so quoted fields with commas work. Skip empty lines and report a clear error for empty input. Done when: the tool reads a CSV file and a piped TSV into an array of rows.

  2. 02

    Compute column widths

    ~1h

    Make every row the same length (padding short rows with empty cells, and warning about them), escape | as \| and turn line breaks inside cells into spaces, then compute each column's width as the longest cell in that column (at least 3, for the separator). Use the display length of strings, so accented letters count as one character. Done when: widths are correct for a sample with different cell lengths.

  3. 03

    Render the table

    ~1h

    Print the header row, the separator row (dashes with colons for alignment: :--- left, :---: center and ---: right, from an --align option such as l,c,r), and the data rows, with each cell padded to its column width (ljust, center or rjust to match the alignment). Done when: the output renders as a correct table on GitHub and looks aligned as plain text.

  4. 04

    Add options

    ~1h

    Use OptionParser for --delimiter, --tsv, --align, --no-header (generating Column 1, Column 2 headers) and --output FILE (writing to standard output by default). Show usage with --help and for invalid options. Done when: every option works, and invalid ones print the usage.

  5. 05

    Test it

    ~1h

    Write Minitest tests: quoted fields with commas, pipes in cells, uneven rows, each alignment, --no-header, accented text widths, and empty input. Done when: the tests pass.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~5h · 5 steps

Tech stack

Standard Library