Created
August 30, 2011 10:36
-
-
Save tamizhgeek/1180625 to your computer and use it in GitHub Desktop.
Diff for adding a sheet_count method to spreadsheet gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/spreadsheet/workbook.rb b/lib/spreadsheet/workbook.rb | |
index 06e17af..eef4f19 100644 | |
--- a/lib/spreadsheet/workbook.rb | |
+++ b/lib/spreadsheet/workbook.rb | |
@@ -56,6 +56,12 @@ module Spreadsheet | |
add_worksheet Worksheet.new(opts) | |
end | |
## | |
+ # Returns the count of total worksheets present. | |
+ # Takes no arguments. Just returns the length of @worksheets array. | |
+ def sheet_count | |
+ @worksheets.length | |
+ end | |
+ ## | |
# The Font at _idx_ | |
def font idx | |
@fonts[idx] | |
diff --git a/test/workbook.rb b/test/workbook.rb | |
index 8869e76..4d701fc 100644 | |
--- a/test/workbook.rb | |
+++ b/test/workbook.rb | |
@@ -17,5 +17,13 @@ module Spreadsheet | |
def test_writer__default_excel | |
assert_instance_of Excel::Writer::Workbook, @book.writer(@io) | |
end | |
+ def test_sheet_count | |
+ @worksheet1 = Excel::Worksheet.new | |
+ @book.add_worksheet @worksheet1 | |
+ assert_equal 1, @book.sheet_count | |
+ @worksheet2 = Excel::Worksheet.new | |
+ @book.add_worksheet @worksheet2 | |
+ assert_equal 2, @book.sheet_count | |
+ end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment