tty-table
tty-table copied to clipboard
Create table directly from Hash
It would be great to add support for data saved in array of hash. Eg:
users = [
{ name: "Foo", city: "XYZ", admin: true },
{ name: "Bar", zip: 987654, city: "ABC"}
]
table = TTY::Table.new(users)
renderer = TTY::Table::Renderer::Unicode.new(table)
renderer.render
Output:
# ┌─────┬───────┬─────┬─────┐
# │name │zip │city │admin│
# ├─────┼───────┼─────┼─────┤
# │Foo │ │XYZ │✔ │
# │Bar │987654 │ABC │ │
# └─────┴───────┴─────┴─────┘
Current implementation expects each header to have value defined for each row. If values are not available then it is to be replaced by nil. For above example sample input would be:
users = [ {
name: ["Foo", "Bar"],
zip: [nil, 987654],
city: ["XYZ", "ABC"],
admin: [true, nil]
} ]
I can submit a PR if required.
Hi @vaibhavatul47; if you have a patch for this completed already, let me know - otherwise I may tackle this.
I had it somewhere on my machine, I'll share the patch shortly.
I know this is old, but @vaibhavatul47 this would be super nice to have :)