csv
csv copied to clipboard
Feature: Encode headers as Keyword list
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.
I realize this could also work for CSV.decode when a internal keys need to be different from header row names.
PR is merged, thanks