Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Format a table in plain text format from a 2 dimensional array.

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

Introducing the Table-formatter gem

sudo gem1.9.1 install table-formatter
require 'table-formatter'
labels = %w(Name Age Address Code)
a = [['Bob', '20', '10, High Street','A342'],
     ['Jane', '23', '12/3, Lawn Market Court', 'B34F'],
     ['Bruce', '32', '63, Cotswalds Way', 'F34AD'],
     ['Michael', '49', '1, Hollwood Way', 'E234D'],
     ['Stephanie', '34', '2, Hampton Court','A234']]

tfo = TableFormatter.new
tfo.source = a
tfo.labels = labels
puts tfo.display

output

--------------------------------------------------------
| Name       | Age | Address                  | Code   |
--------------------------------------------------------
| Bob        | 20  | 10, High Street          | A342   |
| Jane       | 23  | 12/3, Lawn Market Court  | B34F   |
| Bruce      | 32  | 63, Cotswalds Way        | F34AD  |
| Michael    | 49  | 1, Hollwood Way          | E234D  |
| Stephanie  | 34  | 2, Hampton Court         | A234   |
--------------------------------------------------------
Something went wrong with that request. Please try again.