diff options
Diffstat (limited to 'lib/roo/csv.rb')
| -rw-r--r-- | lib/roo/csv.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/roo/csv.rb b/lib/roo/csv.rb index 516def6..4431bc2 100644 --- a/lib/roo/csv.rb +++ b/lib/roo/csv.rb @@ -90,17 +90,23 @@ module Roo def each_row(options, &block) if uri?(filename) each_row_using_tempdir(options, &block) - elsif is_stream?(filename_or_stream) - ::CSV.new(filename_or_stream, options).each(&block) else - ::CSV.foreach(filename, options, &block) + csv_foreach(filename_or_stream, options, &block) end end def each_row_using_tempdir(options, &block) ::Dir.mktmpdir(Roo::TEMP_PREFIX, ENV["ROO_TMP"]) do |tmpdir| tmp_filename = download_uri(filename, tmpdir) - ::CSV.foreach(tmp_filename, options, &block) + csv_foreach(tmp_filename, options, &block) + end + end + + def csv_foreach(path_or_io, options, &block) + if is_stream?(path_or_io) + ::CSV.new(path_or_io, **options).each(&block) + else + ::CSV.foreach(path_or_io, **options, &block) end end |
