Description
Library can be used to render your data to a console. Though it's quite simple, but has many features.
How to use
- Install the gem
bundle add tabled
orgem install tabled
- Add to the application
require 'tabled''
- Pass to the application array of rows. Each row may have any amount of columns and optional footer text.
Params for Tabled instance
Tabled accepts two params. Data which is prohibited and options. Available options:
framed
- optional, default is truerow_separator
- optional, default is-
. Can benil
if you don't need separate rows.titles
- optional parameter with list of columns titles
More examples in demo.rb
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
Result
Helena 20 years Female
John 18 years Male
Alan 23 years Male
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
Result
----------------------------------------------------------------
| Helena 20 years Female |
| John 18 years Male |
| Legendary assassin John Wick (Keanu Reeves). |
| Alan 23 years Male |
----------------------------------------------------------------
Export data to CSV or JSON file
Passed data can be exported as a file. Available formats are csv
and json
. Both parameters are optional. By default, file will be saved in the current directory and with file name tabled.csv
and file format is CSV
.
# CSV
data = [
["Helena", "20 years", "Female"],
]
Tabled
.new(data)
.export_to_csv
# JSON
data = [
["Helena", "20 years", "Female"],
]
Tabled
.new(data, titles: ['Name', 'Age', 'Gender'])
.export_to_csv(format: :json)
Printing CSV files to console
As a part of the gem tabled
binary is included. So, you can basicaly run it like:
tabled print path_to_csv_file
Contributing
- Fork it ( http://github.com/rukomoynikov/tabled/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request