Skip to content

Commit

Permalink
Merge pull request #224 from dlanner/return_enumerator_from_each_row_…
Browse files Browse the repository at this point in the history
…streaming

Return an enumerator when calling each_row_streaming without a block
  • Loading branch information
simonoff committed Jun 10, 2015
2 parents 16dcb43 + 0567d35 commit 8fabd03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,12 @@ def comments(sheet = nil)
# Yield an array of Excelx::Cell
# Takes options for sheet, pad_cells, and max_rows
def each_row_streaming(options = {})
sheet_for(options.delete(:sheet)).each_row(options) { |row| yield row }
sheet = sheet_for(options.delete(:sheet))
if block_given?
sheet.each_row(options) { |row| yield row }
else
sheet.to_enum(:each_row, options)
end
end

private
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/roo/excelx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -447,5 +447,11 @@
expect(index).to eq 4
end
end

context 'without block passed' do
it 'returns an enumerator' do
expect(subject.each_row_streaming).to be_a(Enumerator)
end
end
end
end

0 comments on commit 8fabd03

Please sign in to comment.