piotrmurach / tty

Toolkit for developing sleek command line apps.
https://ttytoolkit.org
MIT License
2.5k stars 78 forks source link

suggestion: csv #24

Closed gurgeous closed 6 years ago

gurgeous commented 8 years ago

Another one - TTY could support csv reading & writing. Arrays of hashes/structs/ostructs can be written to csv, and reading a csv returns an array of structs.

def csv_read(path)
def csv_write(path, rows)
def csv_to_s(rows)

Let me know if you are interested.

piotrmurach commented 8 years ago

I'm interested but I believe this kind of functionality has it's place in external tty plugins. Also, this requirement seems connected with what tty-table tries to achieve. It's easy to see how tabular data could be exported to csv or any other format. Same goes for reading data from a given format. It's worth taking time to think of different formatting types tsv, latex etc... and how things can be handled more generically.

gurgeous commented 8 years ago

I'm usually dealing with arrays of hashes, structs, or ostructs. They are somewhat interchangeable and more useful than plain old arrays. Is it worth modifying tty-table to take a similar approach?

I'd be happy to try to bake this into a tty-csv if you think that's appropriate. Personally I rely heavily on CSV files and rarely use the other variants, but I'm sure everyone has a different approach.

piotrmurach commented 6 years ago

Hi Adam,

I'm going to close this issue due to the fact that it's outside of the tty scope. I believe this is a useful idea but at the same time tty focuses on helping build command line interfaces rather than process data per say.

In addition, I've seen quite a few libraries that attempt to solve this problem or similar thereof. For example, https://github.com/rom-rb/rom is an extremely powerful object mapper which has csv adaptor https://github.com/rom-rb/rom-csv. Also, https://github.com/buren/honey_format seems a recent attempt at working with csv more in line with what you want - at least having a cursory look.

gurgeous commented 6 years ago

Not a problem, thanks for considering it. honey_format looks pretty neat and may fill the gap. I have basic support for this in my scripto helper as well.