Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix :parse method with :clean option #184

Merged
merged 1 commit into from
Mar 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/roo/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,14 @@ def read_cells(sheet = default_sheet)
@last_column[sheet] -= 1
end
end

def clean_sheet(sheet)
read_cells(sheet)

@cell.each_pair do |coord, value|
@cell[coord] = sanitize_value(value) if value.is_a?(::String)
end

@cleaned[sheet] = true
end
end
8 changes: 8 additions & 0 deletions lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ def each_row_streaming(options={})

private

def clean_sheet(sheet)
@sheets_by_name[sheet].cells.each_pair do |coord, value|
@sheets_by_name[sheet].cells[coord] = sanitize_value(value) if value.is_a?(::String)
end

@cleaned[sheet] = true
end

# Extracts all needed files from the zip file
def process_zipfile(tmpdir, zipfilename)
@sheet_files = []
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/roo/csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
end
end

describe '#parse_with_clean_option' do
subject do
csv.parse(options)
end
context 'with clean: true' do
let(:options) { {clean: true} }
let(:path) { 'test/files/parse_with_clean_option.csv' }

it "doesn't blow up" do
expect { subject }.to_not raise_error
end
end
end

describe '#csv_options' do
context 'when created with the csv_options option' do
let(:options) do
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/roo/excelx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@
end
end

describe '#parse_with_clean_option' do
let(:path) { 'test/files/parse_with_clean_option.xlsx' }
let(:options) { {clean: true} }

context 'with clean: true' do

it 'does not raise' do
expect do
xlsx.parse(options)
end.not_to raise_error
end
end
end

describe '#sheets' do
let(:path) { 'test/files/numbers1.xlsx' }

Expand Down
1 change: 1 addition & 0 deletions test/files/parse_with_clean_option.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nameRobert Eshleman
Expand Down
Binary file added test/files/parse_with_clean_option.xlsx
Binary file not shown.