Skip to content

Commit

Permalink
Merge pull request #184 from stevendaniels/error-parsing-with-clean
Browse files Browse the repository at this point in the history
Fix :parse method with :clean option
  • Loading branch information
simonoff committed Mar 23, 2015
2 parents 1fc3c37 + c007842 commit 4cce70a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
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.

0 comments on commit 4cce70a

Please sign in to comment.