Skip to content

Commit

Permalink
Merge pull request roo-rb#297 from stevendaniels/allow_streaming_for_csv
Browse files Browse the repository at this point in the history
Allow streaming for Roo::CSV
  • Loading branch information
stevendaniels committed Feb 9, 2016
2 parents d348264 + 67fda22 commit 6aa6a73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/roo/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def each_row(options, &block)
tmp_filename = download_uri(filename, tmpdir)
CSV.foreach(tmp_filename, options, &block)
end
elsif is_stream?(filename_or_stream)
CSV.new(filename_or_stream, options).each(&block)
else
CSV.foreach(filename, options, &block)
end
Expand Down Expand Up @@ -117,4 +119,6 @@ def clean_sheet(sheet)

@cleaned[sheet] = true
end

alias_method :filename_or_stream, :filename
end
7 changes: 7 additions & 0 deletions spec/lib/roo/csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
end
end

describe '.new with stream' do
let(:csv) { Roo::CSV.new(File.read(path)) }
it 'creates an instance' do
expect(csv).to be_a(Roo::CSV)
end
end

describe '#parse' do
subject do
csv.parse(options)
Expand Down

0 comments on commit 6aa6a73

Please sign in to comment.