Skip to content

Commit

Permalink
Direct users to Workbook.open
Browse files Browse the repository at this point in the history
  • Loading branch information
martijn committed Apr 16, 2021
1 parent 41e584d commit 8b70e86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/xsv/workbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def self.open(data, **kws)
# trim_empty_rows (false) Scan sheet for end of content and don't return trailing rows
#
def initialize(zip, trim_empty_rows: false)
raise ArgumentError, "Passed argument is not an instance of Zip::File. Did you mean to use Workbook.open?" unless zip.is_a?(Zip::File)

@zip = zip
@trim_empty_rows = trim_empty_rows

Expand Down
6 changes: 6 additions & 0 deletions test/workbook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ def test_open_without_shared_strings
@workbook = Xsv::Workbook.open("test/files/no-shared-strings.xlsx")
refute_empty @workbook.sheets
end

def test_new_instead_of_open
assert_raises ArgumentError do
Xsv::Workbook.new "not a Zip::File instance"
end
end
end

0 comments on commit 8b70e86

Please sign in to comment.