csv icon indicating copy to clipboard operation
csv copied to clipboard

Feature: Encode headers as Keyword list

Open h4cc opened this issue 7 years ago • 1 comments

Idea for a feature:

CSV.encode could accept a Keyword list as headers next to a list or true. The keys of that list will be used as the keys for the rows, but the value will be the value used for the header row name in CSV output.

Example:

CSV.encode([%{city: "Hamburg", zip: "22009"}], headers: [city: "Stadt", zip: "Postleitzahl"])
["Stadt,Postleitzahl\r\n", "Hamburg,22009\r\n"]

This would be very useful when the CSV headers do not match the internals keys. It could also be used to internationalize header row names.

h4cc avatar Aug 15 '18 10:08 h4cc

I realize this could also work for CSV.decode when a internal keys need to be different from header row names.

h4cc avatar Aug 15 '18 10:08 h4cc

PR is merged, thanks

beatrichartz avatar Sep 17 '22 02:09 beatrichartz