Gerald Bauer
2018-10-17 06:02:01 UTC
Hello,
I've published the tabreader library / gem version 1.0 [1]
that lets you read in tabular datafiles in text in the tabular (TAB) format.
Yes, it's as simple as:
line = "1\t2\t3"
values = line.split( "\t" )
pp values
# => ["1","2","3"]
or the "magic" packaged up in `TabReader`:
line = "1\t2\t3"
values = Tab.parse_line( line ) ## or TAB.parse_line or
TabReader.parse_line
pp values
# => ["1","2","3"]
or use the convenience helpers:
txt <<=TXT
1\t2\t3
4\t5\t6
TXT
records = Tab.parse( txt ) ## or TAB.parse or TabReader.parse
pp records
# => [["1","2","3"],
# ["4","5","6"]]
or
records = Tab.read( "values.tab" ) ## or TAB.read or TabReader.read
pp records
# => [["1","2","3"],
# ["4","5","6"]]
or
Tab.foreach( "values.tab" ) do |rec| ## or TAB.foreach or TabReader.foreach
pp rec
end
# => ["1","2","3"]
# => ["4","5","6"]
and so on.
Happy data wrangling with ruby. Cheers. Prost.
PS: The FAQ in the README includes:
- Q: Why NOT use Csv.read( sep: "\t" )?
- Q: What's the tabulator (TAB) format?
- Q: Why tab?
- Q: Why NOT tab?
[1] https://github.com/csv11/tabreader
Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
I've published the tabreader library / gem version 1.0 [1]
that lets you read in tabular datafiles in text in the tabular (TAB) format.
Yes, it's as simple as:
line = "1\t2\t3"
values = line.split( "\t" )
pp values
# => ["1","2","3"]
or the "magic" packaged up in `TabReader`:
line = "1\t2\t3"
values = Tab.parse_line( line ) ## or TAB.parse_line or
TabReader.parse_line
pp values
# => ["1","2","3"]
or use the convenience helpers:
txt <<=TXT
1\t2\t3
4\t5\t6
TXT
records = Tab.parse( txt ) ## or TAB.parse or TabReader.parse
pp records
# => [["1","2","3"],
# ["4","5","6"]]
or
records = Tab.read( "values.tab" ) ## or TAB.read or TabReader.read
pp records
# => [["1","2","3"],
# ["4","5","6"]]
or
Tab.foreach( "values.tab" ) do |rec| ## or TAB.foreach or TabReader.foreach
pp rec
end
# => ["1","2","3"]
# => ["4","5","6"]
and so on.
Happy data wrangling with ruby. Cheers. Prost.
PS: The FAQ in the README includes:
- Q: Why NOT use Csv.read( sep: "\t" )?
- Q: What's the tabulator (TAB) format?
- Q: Why tab?
- Q: Why NOT tab?
[1] https://github.com/csv11/tabreader
Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>