Table

Methods

Getter and Setter Methods

NOTE: These methods's names are the same as their respective attributes. To set a specific attribute during the instantiation of a Prettier::Table object, use its method's name. For instance, to set title, Prettier::Table.new(title => "Table's title"). Thus, all methods listed here have an associated attribute that can be set during object construction.

Style of Table

Data Input Methods

Plain Text String methods

Miscellaneous Methods

Name

Prettier::Table, a simple Raku module to make it quick and easy to represent tabular data in visually appealing ASCII tables.

This is a fork of Luis F Uceta's Prettier::Table which is itself a port of the Kane Blueriver's PTable library for Python. I (masukomi) have modifed it to use ASCII Box drawing characters so as to make it "prettier".

Synopsis

Example 1:

use Prettier::Table;

my $table = Prettier::Table.new:
    title => "Australian Cities",
    field-names => ["City name", "Area", "Population", "Annual Rainfall"],
    sort-by => 'Area',
    align => %('City name' => 'l'),
;

given $table {
    .add-row: ["Adelaide",  1295,  1158259,  600.5 ];
    .add-row: ["Brisbane",  5905,  1857594,  1146.4];
    .add-row: ["Darwin",    112,   120900,   1714.7];
    .add-row: ["Hobart",    1357,  205556,   619.5 ];
    .add-row: ["Sydney",    2058,  4336374,  1214.8];
    .add-row: ["Melbourne", 1566,  3806092,  646.9 ];
    .add-row: ["Perth",     5386,  1554769,  869.4 ];
}

say $table;

Output:

<img alt="actual rendering" src="https://github.com/masukomi/Prettier-Table/blob/main/images/australian_cities.png?raw=true" />

(GitHub displays the raw text incorrectly)


    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                Australian Cities                β”‚
    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
    β”‚ City name β”‚ Area β”‚ Population β”‚ Annual Rainfall β”‚
    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
    β”‚ Darwin    β”‚ 112  β”‚   120900   β”‚      1714.7     β”‚
    β”‚ Adelaide  β”‚ 1295 β”‚  1158259   β”‚      600.5      β”‚
    β”‚ Hobart    β”‚ 1357 β”‚   205556   β”‚      619.5      β”‚
    β”‚ Melbourne β”‚ 1566 β”‚  3806092   β”‚      646.9      β”‚
    β”‚ Sydney    β”‚ 2058 β”‚  4336374   β”‚      1214.8     β”‚
    β”‚ Perth     β”‚ 5386 β”‚  1554769   β”‚      869.4      β”‚
    β”‚ Brisbane  β”‚ 5905 β”‚  1857594   β”‚      1146.4     β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Example 2:

use Prettier::Table;

my $table = Prettier::Table.new;

given $table {
    .add-column('Planet', ['Earth', 'Mercury', 'Venus', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']);
    .add-column('Position', [3, 1, 2, 4, 5, 6, 7, 8])
    .add-column('Known Satellites', [1, 0, 0, 2, 79, 82, 27, 14]);
    .add-column('Orbital period (days)', [365.256, 87.969, 224.701, 686.971, 4332.59, 10_759.22, 30_688.5, 60_182.0]);
    .add-column('Surface gravity (m/s)', [9.806, 3.7, 8.87, 3.721, 24.79, 10.44, 8.69, 11.15]);
}

$table.title('Planets in the Solar System');
$table.align(%(:Planet<l>));
$table.float-format(%('Orbital period (days)' => '-10.3f', 'Surface gravity (m/s)' => '-5.3f'));
$table.sort-by('Position');
# If you wish to change any of the characters used in the border
# you could do something like this.
# $table.junction-char('*');

put $table;

Output:

<img alt="actual rendering" src="https://github.com/masukomi/Prettier-Table/blob/main/images/planets_of_the_solar_system.png?raw=true" />

(GitHub displays the raw text incorrectly)


    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                    Planets in the Solar System                     β”‚
    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
    β”‚  Planet β”‚ Position β”‚ Orbital period (days) β”‚ Surface gravity (m/s) β”‚
    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
    β”‚  Earth  β”‚    3     β”‚        365.256        β”‚         9.806         β”‚
    β”‚ Mercury β”‚    1     β”‚         87.969        β”‚          3.7          β”‚
    β”‚  Venus  β”‚    2     β”‚        224.701        β”‚          8.87         β”‚
    β”‚   Mars  β”‚    4     β”‚        686.971        β”‚         3.721         β”‚
    β”‚ Jupiter β”‚    5     β”‚        4332.59        β”‚         24.79         β”‚
    β”‚  Saturn β”‚    6     β”‚        10759.22       β”‚         10.44         β”‚
    β”‚  Uranus β”‚    7     β”‚        30688.5        β”‚          8.69         β”‚
    β”‚ Neptune β”‚    8     β”‚         60182         β”‚         11.15         β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Installation

Using zef:

zef install Prettier::Table

From source:

$ git clone
$ cd raku-pretty-table
$ zef install .

Quickstart

Prettier::Table supports two kinds of usage:

As a module

use Prettier::Table;
my $x = Prettier::Table.new;

Check out the attributes in Prettier::Table to see the full list of things that can be set / configured. Most notably the *-char attributes, used to control the look of the border. Additionally, the named parameters in the get-string method.

AUTHORS

LICENSE

MIT. See LICENSE file.

); }

Prettier::Table v1.0.0

A simple Raku module to generate smooth looking ASCII tables

Authors

  • Luis F. Uceta
  • masukomi

License

MIT

Dependencies

Text::Wrap

Test Dependencies

Provides

  • Prettier::Table
  • Prettier::Table::Constrains

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.