Project

tabled

0.0
The project is in a healthy, maintained state
Library can be used to render your data to a console. Being quite simple it has many features.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Tabled

Gem Version CI is pasing for ruby 2.6 - 3.0 Downloads

Tabled is a versatile gem designed for rendering tabular data in a console. It offers various features to make data presentation simple and customizable.

Table of Contents

  • Installation
  • Usage
  • Options
  • Examples
  • Exporting Data
  • Printing CSV or JSON Files
  • Contributing

Installation

bundle add tabled
# or
gem install tabled

Usage

To use Tabled in your application, follow these steps:

  1. Require the gem in your code:
    require 'tabled'
  2. Pass an array of rows to the application. Each row can contain any number of columns and optional footer text.

Options

Tabled accepts the following options:

  • framed (optional, default: true): Specify if the output should have frames.
  • row_separator (optional, default: "-"): Set the character for row separators or set it to nil if you don't want to separate rows.
  • titles (optional): Provide a list of column titles.

Examples

Here are some examples to help you get started:

Simple Data Structure

data = [
  ["Helena", "20 years", "Female"],
  ["John", "18 years", "Male"],
  ["Alan", "23 years", "Male"],
]

Tabled.new(data, framed: false, row_separator: nil).print_to_console

Using Footer Inside a Row

data = [
  ["Helena", "20 years", "Female"],
  ["John", "18 years", "Male", { footer: "Legendary assassin John Wick (Keanu Reeves)." }],
  ["Alan", "23 years", "Male"],
]

Tabled.new(data, row_separator: nil).print_to_console

Exporting Data

You can export the data in CSV or JSON formats. By default, the file is saved in the current directory with the file name "tabled.csv" (CSV format).

# Export to CSV
Tabled.new(data).export_to_file

# Export to JSON
Tabled.new(data, titles: ['Name', 'Age', 'Gender']).export_to_file(format: :json)

# Customize file name
Tabled.new(data, titles: ['Name', 'Age', 'Gender']).export_to_file(file_name: 'my_file.json')

Printing CSV or JSON Files

As part of the gem, the tabled binary is included. You can run it like this:

tabled print path_to_[csv|json]_file

Contributing

  1. Fork it ( http://github.com/rukomoynikov/tabled/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request