-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CSV::TSV class for tab-separated values #319
Conversation
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").read BTW, is |
@kou Thanks for the feedback! Updated and pushed a new commit. |
Could you add some tests for this change? |
@kou Thanks, added tests and updated the description. |
run-test.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Did you run added tests on your local machine? Or did you enable GitHub Actions on your fork? We need to add |
Thanks. The fix was a straightforward namespace correction that aligns the test code with the actual implementation in |
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:
(#272)
Changes from Previous Version
The implementation has been significantly simplified:
initialize
to set default separator