Skip to content

Commit

Permalink
fixes roo-rb#389 #to_csv changed predefined arguments and add documen…
Browse files Browse the repository at this point in the history
…tation
  • Loading branch information
Mifrill committed Oct 17, 2018
1 parent 5fc4378 commit 837d273
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ sheet.to_xml
sheet.to_yaml
```

`#to_csv` acceptable for the parameters:

# puts csv format content into a specified file
sheet.to_csv(filename: "/path/file.txt)

# specify the custom separator for the content
sheet.to_csv(separator: ":")

### Excel (xlsx and xlsm) Support

Stream rows from an Excelx spreadsheet.
Expand Down
2 changes: 1 addition & 1 deletion lib/roo/formatters/csv.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Roo
module Formatters
module CSV
def to_csv(filename = nil, separator = ",", sheet = default_sheet)
def to_csv(sheet = default_sheet, separator: ",", filename: nil)
if filename
File.open(filename, "w") do |file|
write_csv_content(file, sheet, separator)
Expand Down
9 changes: 8 additions & 1 deletion spec/lib/roo/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,15 @@ def sheets
expect(spreadsheet.to_csv).to eq(expected_csv)
end

it 'should convert the spreadsheet to csv and put it into a file' do
file = Tempfile.new("test")

expect(spreadsheet.to_csv(filename: file)).to be_truthy
expect(file.read).to eq(expected_csv)
end

it 'should convert the spreadsheet to csv using the separator when is passed on the parameter' do
expect(spreadsheet.to_csv(nil, ';')).to eq(expected_csv_with_semicolons)
expect(spreadsheet.to_csv(separator: ';')).to eq(expected_csv_with_semicolons)
end
end
end

0 comments on commit 837d273

Please sign in to comment.