Skip to content

Commit

Permalink
fixes #389 #to_csv: changed predefined arguments and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mifrill committed Nov 14, 2018
1 parent 8f65109 commit 23e831d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ sheet.to_xml
sheet.to_yaml
```

You can specified file as default argument to `#to_csv`:

```ruby
# puts csv format content into a specified file
sheet.to_csv(File.new("/dev/null"))
```

also you can specify the custom separator for the content:

```ruby
sheet.to_csv(separator: ":") # "," is used by default
```

### 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(filename = nil, separator: ",", sheet: default_sheet)
if filename
File.open(filename, "w") do |file|
write_csv_content(file, sheet, separator)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/roo/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def sheets
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 23e831d

Please sign in to comment.