diff --git a/lib/saxlsx/rows_collection.rb b/lib/saxlsx/rows_collection.rb index ae07e07..102b2e1 100644 --- a/lib/saxlsx/rows_collection.rb +++ b/lib/saxlsx/rows_collection.rb @@ -12,7 +12,11 @@ def initialize(index, file_system, workbook) end def each(&block) - RowsCollectionParser.parse @index, @sheet, @workbook, &block + if block + RowsCollectionParser.parse @index, @sheet, @workbook, &block + else + to_enum + end end def count diff --git a/lib/saxlsx/shared_string_collection.rb b/lib/saxlsx/shared_string_collection.rb index aaca9bb..5f63bef 100644 --- a/lib/saxlsx/shared_string_collection.rb +++ b/lib/saxlsx/shared_string_collection.rb @@ -9,7 +9,11 @@ def initialize(file_system) end def each(&block) - SharedStringCollectionParser.parse @file_system, &block + if block + SharedStringCollectionParser.parse @file_system, &block + else + to_enum + end end end diff --git a/lib/saxlsx/sheet_collection.rb b/lib/saxlsx/sheet_collection.rb index ae17a9c..61dfa60 100644 --- a/lib/saxlsx/sheet_collection.rb +++ b/lib/saxlsx/sheet_collection.rb @@ -10,7 +10,11 @@ def initialize(file_system, workbook) end def each(&block) - SheetCollectionParser.parse @file_system, @workbook, &block + if block + SheetCollectionParser.parse @file_system, @workbook, &block + else + to_enum + end end end diff --git a/lib/saxlsx/style_collection.rb b/lib/saxlsx/style_collection.rb index 3e8ce90..57d285c 100644 --- a/lib/saxlsx/style_collection.rb +++ b/lib/saxlsx/style_collection.rb @@ -9,7 +9,11 @@ def initialize(file_system) end def each(&block) - StyleCollectionParser.parse @file_system, &block + if block + StyleCollectionParser.parse @file_system, &block + else + to_enum + end end end diff --git a/spec/sheet_spec.rb b/spec/sheet_spec.rb index a1ccbba..784c7f4 100644 --- a/spec/sheet_spec.rb +++ b/spec/sheet_spec.rb @@ -27,6 +27,16 @@ end end + it 'handle enumeration' do + indexes = [] + Workbook.open filename do |w| + w.sheets[0].rows.each.with_index do |r, i| + indexes << i + end + end + indexes.should eq [0, 1, 2, 3, 4, 5, 6] + end + it 'Rows content' do Workbook.open filename do |w| w.sheets[0].tap do |s|