Skip to content

Instantly share code, notes, and snippets.

@supremebeing7
Created April 22, 2018 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supremebeing7/c027599ceff6a536e6b378dcb3e19782 to your computer and use it in GitHub Desktop.
Save supremebeing7/c027599ceff6a536e6b378dcb3e19782 to your computer and use it in GitHub Desktop.
roo gem parse issues
require 'roo'
csv = Roo::Spreadsheet.open("sample.csv")
csv.parse
# => [["row1col1", "row1col2", "row1col3"],
# ["row2col1", "row2col2", "row2col3"],
# ["row3col1", "row3col2", "row3col3"]]
csv.parse(headers: true)
# => [{"header1"=>"header1", "header2"=>"header2", "header3"=>"header3"},
# {"header1"=>"row1col1", "header2"=>"row1col2", "header3"=>"row1col3"},
# {"header1"=>"row2col1", "header2"=>"row2col2", "header3"=>"row2col3"},
# {"header1"=>"row3col1", "header2"=>"row3col2", "header3"=>"row3col3"}]
csv.to_a
# => [["header1", "header2", "header3"],
# ["row1col1", "row1col2", "row1col3"],
# ["row2col1", "row2col2", "row2col3"],
# ["row3col1", "row3col2", "row3col3"]]
csv.row(1)
# => ["header1", "header2", "header3"]
header1 header2 header3
row1col1 row1col2 row1col3
row2col1 row2col2 row2col3
row3col1 row3col2 row3col3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment