-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
#4148 add values_at method for CSV::Row #4157
Conversation
src/csv.cr
Outdated
# Raises `IndexError` if any column doesn't exist | ||
# The behavior of returning a tuple is similar to `Hash#values_at` | ||
def values_at(*columns : Int) | ||
columns.map { |column| self.[](column) } |
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.
self[column]
src/csv.cr
Outdated
# Raises `CSV::Error` if headers were not requested | ||
# The behavior of returning a tuple is similar to `Hash#values_at` | ||
def values_at(*headers : String) | ||
headers.map { |header| self.[](header) } |
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.
ditto
@Sija I have updated the PR according to your comment. My local test was good, but I saw that Travis CI had failed. Not sure whether it's related to my PR. Let me know if there is anything I can do. |
Hi @need47, the failures are because of formatting. If you run
There should be changes to submit and will make CI pass. At least linux one. There are currently some issues regarding OSX CI. |
All checks passed except for OSX CI. Just FYI, I did compile LLVM (version 3.9.1) without the OSX platform. |
I am reading the spec/std/csv/csv_spec.cr and found an interesting use of CSV.
a csv object can call [] directly as if it was a row. So shall I also add CSV#values_at() methods, in addition to CSV::Row#values_at() in this PR? |
@need47 Sure! mimic how |
…spec.cr 3) removed the unnecessary file spec/std/csv/csv_values_at_spec.cr
I have added CSV#values_at and CI passed. |
@need47 Sorry, I've just noticed that the specs should be at |
…v_parse_spec.cr to spec/std/csv_spec.cr
specs moved and CI passed. |
Merged! Thanks @need47 for your first contribution to crystal |
This PR adds the following methods to CSV::Row in (src/csv.cr)
values_at(*columns : Int)
values_at(*headers: String)
to retrieve multiple values at given columns or corresponding to headers.
A spec file was also provided at: spec/std/csv/csv_values_at_spec.cr
It's my first PR ever. If I was doing something wrong, please kindly let me know