martijn/xsv

hash mode as an argument or parse_headers! can return self

Closed this issue · 1 comments

It is possible to write the following for array mode but for hash mode one is forced to create intermediate variables.

Xsv::Workbook.open('file.xlsx').sheets[0].each_row do |row|
  row # => ["value1", "value2"]
end

If there was a :mode argument to open function or if the function parse_headers! would return self instead of a fixed true (or both? 🤔) this would let the user do one of the following:

Xsv::Workbook.open('file.xlsx', mode: :hash).sheets[0].each_row do |row|
  row # => {"header1" => "value1", "header2" => "value2"}
end

Xsv::Workbook.open('file.xlsx').sheets[0].parse_headers!.each_row do |row|
  row # => {"header1" => "value1", "header2" => "value2"}
end

I created a PR for the easy option ☺️