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

Allow streaming for Roo::CSV #297

Merged
merged 1 commit into from
Feb 9, 2016
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
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