Closed jsxs0 closed 3 days ago
Hmm. Do we need to override all class methods? Can we just override TSV#initialize
?
diff --git a/lib/csv.rb b/lib/csv.rb
index f6eb32a..8c71b4d 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -2979,6 +2979,12 @@ class CSV
end
end
+class TSV < CSV
+ def initialize(data, **options)
+ super(data, **({col_sep: "\t"}.merge(options)))
+ end
+end
+
# Passes +args+ to CSV::instance.
#
# CSV("CSV,data").read
BTW, is CSV::TSV
intentional? (::TSV
may be easy to use but it may break other library's API that defines ::TSV
...)
@kou Thanks for the feedback! Updated and pushed a new commit.
Could you add some tests for this change? Could you update the PR description for the latest changes?
Could you add some tests for this change? Could you update the PR description for the latest changes?
@kou Thanks, added tests and updated the description.
Did you run added tests on your local machine? Or did you enable GitHub Actions on your fork?
We need to add CSV::
to all TSV
references.
Did you run added tests on your local machine? Or did you enable GitHub Actions on your fork?
We need to add
CSV::
to allTSV
references.
Thanks. The fix was a straightforward namespace correction that aligns the test code with the actual implementation in lib/csv.rb
.
Thanks.
Add TSV class for tab-separated files support
This PR adds a lightweight TSV class that provides first-class support for tab-separated files through a simple inheritance mechanism from the CSV class.
Implementation
The implementation has been simplified to only override the
initialize
method, which sets the default column separator to tab (\t
). This minimalist approach maintains full compatibility with CSV while providing convenient TSV handling:Features
Example Usage
Motivation
This change is motivated by:
(https://github.com/ruby/csv/issues/272)
Changes from Previous Version
The implementation has been significantly simplified:
initialize
to set default separator