Skip to content
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.parse - Support Headers #15258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Zeljko-Predjeskovic
Copy link
Contributor

Based on issue #15170 requirements and solution recommendations.

closes #15170, if this PR is accepted and merged.

@Zeljko-Predjeskovic Zeljko-Predjeskovic changed the title Added CSV.parse - Support Headers Add CSV.parse - Support Headers Dec 9, 2024
src/csv/parser.cr Outdated Show resolved Hide resolved
spec/std/csv/csv_parse_spec.cr Outdated Show resolved Hide resolved
@@ -19,6 +19,16 @@ class CSV::Parser
rows
end

def parse_to_h : Array(Hash(String, String))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realizing that this is not a good place since it parses the remaining rows and that means that every row could be the headers. Didnt notice since i tested only CSV and not the parser itself. Either when using this methode, rewind the parser to the begining or somehow extract the header.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit dubious about rewinding to get the headers. I think the caller can make sure the CSV parser is where it needs to be before calling to_h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSV.parse - Support Headers
2 participants