beatrichartz/csv

Double quotes on numbers

ch33foong opened this issue · 2 comments

Hi,

how can I force number field to be double quoted?

Does the library support this?

Thanks.

Sure, when encoding you can define the way the data gets encoded:

defimpl CSV.Encode, for: MyData do
  def encode(%MyData{has: fun}, env \\ []) do
    "so much #{fun}" |> CSV.Encode.encode(env)
  end
end

So you should also be able to do:

defimpl CSV.Encode, for: Integer do
  def encode(integer, env \\ []) do
    "#{integer}" |> CSV.Encode.encode(env)
  end
end

Is this kind of protocol available for Decoding also?