Uh oh!
There was an error while loading. Please reload this page.
Add CSV::TSV class for tab-separated values - #319
Conversation
kou
commented
Oct 30, 2024
Hmm. Do we need to override all class methods? Can we just override 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").readBTW, is |
jsxs0
commented
Oct 30, 2024
@kou Thanks for the feedback! Updated and pushed a new commit. |
kou
commented
Nov 14, 2024
Could you add some tests for this change? |
jsxs0
commented
Nov 14, 2024
@kou Thanks, added tests and updated the description. |
There was a problem hiding this comment.
Why do we need to change this file?
I think that we don't need to change this file but if you think that we need to change this file, could you open a separated PR?
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
kou
commented
Nov 14, 2024
Did you run added tests on your local machine? Or did you enable GitHub Actions on your fork? We need to add |
jsxs0
commented
Nov 25, 2024
Thanks. The fix was a straightforward namespace correction that aligns the test code with the actual implementation in |
kou
commented
Nov 25, 2024
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
initializemethod, 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:
(#272)
Changes from Previous Version
The implementation has been significantly simplified:
initializeto set default separator