Skip to content

Latest commit

 

History

History
110 lines (81 loc) · 3.02 KB

README.md

File metadata and controls

110 lines (81 loc) · 3.02 KB

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

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

Print Ruby CSV records

csv = CSV.parse(<<~ROWS, headers: true)
  Bob,Engineering,1000
  Jane,Sales,2000
  John,Management,5000
ROWS

Tabled.from_csv(csv: csv, framed: true).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

Development process in Docker

Run docker compose run --build --rm app bash to get full packed dev environment for the gem developing.