Skip to content

rfauver/TablePuts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TablePuts

Gem Version

Print nice tables in a ruby console

Installation

# Install as a standalone gem
$ gem install table_puts

# Or with bundler
gem "table_puts" # In your Gemfile
$ bundle install

Usage

Array of Hashes

TablePuts.call(data)

TablePuts prints data that is in the form of an array of hashes all with the same keys

For example:

[ { title: 'Super Mario Bros', release_year: 1985 },
  { title: 'Sonic the Hedgehog', release_year: 1991 }]

would print as

+--------------------+--------------+
| title              | release_year |
+--------------------+--------------+
| Super Mario Bros   |         1985 |
| Sonic the Hedgehog |         1991 |
+--------------------+--------------+

CSV

You can also pass in the path to a CSV file:

TablePuts.csv('path/to/your.csv')

Configuration

Both TablePuts.call and TablePuts.csv take optional parameters min_width and max_width that sets the minimum and maximum allowed character widths of each column.

TablePuts.call(data, min_width: 10, max_width: 15)

By default min_width is 0 and max_width is 20. You can change these defaults in a configuration block.

TablePuts.configuration do |config|
  config.min_column_width = # new minimum default
  config.max_column_width = # new maximum default
end

About

Print nice tables in a ruby console

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages