Skip to content

Commit

Permalink
Merge pull request #576 from tsuchiyaisshin/feature/return_enumerator…
Browse files Browse the repository at this point in the history
…_each_with_page

Roo::Base#each_with_pagename returns Enumerator Object
  • Loading branch information
kakubin authored Jan 20, 2023
2 parents 3ae128f + 3d5fdb8 commit 20011af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Unreleased

### Changed/Added
- Roo::Base#each_with_pagename returns Enumerator Object [576](https://github.com/roo-rb/roo/pull/576)

## [2.9.0] 2022-03-19

### Changed/Added
Expand Down
6 changes: 4 additions & 2 deletions lib/roo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,10 @@ def sheet(index, name = false)

# iterate through all worksheets of a document
def each_with_pagename
sheets.each do |s|
yield sheet(s, true)
Enumerator.new do |yielder|
sheets.each do |s|
yielder << sheet(s, true)
end
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/lib/roo/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ def sheets
end
end

describe '#each_with_pagename' do
it 'should return an enumerator with all the rows' do
each_with_pagename = spreadsheet.each_with_pagename
expect(each_with_pagename).to be_a(Enumerator)
expect(each_with_pagename.to_a.last).to eq([spreadsheet.default_sheet, spreadsheet])
end
end

describe '#each' do
it 'should return an enumerator with all the rows' do
each = spreadsheet.each
Expand Down

0 comments on commit 20011af

Please sign in to comment.