From 66c0bbd6fd6b96f375c2d2e7c9e7379fb44e3c3c Mon Sep 17 00:00:00 2001 From: Jasveen Date: Mon, 28 Oct 2024 16:58:59 +0900 Subject: [PATCH] Add :sep alias for :col_sep --- lib/csv.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/csv.rb b/lib/csv.rb index f6eb32a6..c1523347 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -2033,6 +2033,7 @@ def create_stringio(str, mode, opts) # def initialize(data, col_sep: ",", + sep: nil, row_sep: :auto, quote_char: '"', field_size_limit: nil, @@ -2059,6 +2060,11 @@ def initialize(data, write_empty_value: "") raise ArgumentError.new("Cannot parse nil as CSV") if data.nil? + if sep && col_sep != "," + raise ArgumentError, "Cannot specify both :sep and :col_sep" + end + actual_sep = sep || col_sep + if data.is_a?(String) if encoding if encoding.is_a?(String) @@ -2094,7 +2100,7 @@ def initialize(data, max_field_size = field_size_limit - 1 end @parser_options = { - column_separator: col_sep, + column_separator: actual_sep, row_separator: row_sep, quote_character: quote_char, max_field_size: max_field_size,