Created
March 6, 2014 19:30
-
-
Save JEG2/9397561 to your computer and use it in GitHub Desktop.
An example of parsing CSV-like data using | characters as separators and keeping header support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
headers = nil | |
File.foreach(path) do |line| | |
fields = line.split(“|”) | |
if headers | |
row = headers.zip(fields) | |
# … | |
else | |
headers = fields | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment