From 835368e1d29c1530f00bf9caa07704b17370e38f Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 24 Nov 2014 01:47:08 -0800 Subject: [PATCH] Inline and simplify OpenOffice.process_zipfile --- lib/roo/open_office.rb | 25 ++++++------------------- test/test_roo.rb | 2 +- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/lib/roo/open_office.rb b/lib/roo/open_office.rb index 0dd4d24d..4089a321 100644 --- a/lib/roo/open_office.rb +++ b/lib/roo/open_office.rb @@ -3,23 +3,6 @@ require 'cgi' class Roo::OpenOffice < Roo::Base - class << self - def process_zipfile(tmpdir, zip, path='') - if zip.file.file? path - if path == "content.xml" - File.write(File.join(tmpdir, 'roo_content.xml'), zip.read(path), mode: 'wb') - end - else - unless path.empty? - path += '/' - end - zip.dir.foreach(path) do |filename| - process_zipfile(tmpdir, zip, path+filename) - end - end - end - end - # initialization and opening of a spreadsheet file # values for packed: :zip def initialize(filename, options={}) @@ -30,8 +13,12 @@ def initialize(filename, options={}) @tmpdir = make_tmpdir(filename.split('/').last, options[:tmpdir_root]) @filename = local_filename(filename, @tmpdir, packed) #TODO: @cells_read[:default] = false - Roo::ZipFile.open(@filename) do |zip| - self.class.process_zipfile(@tmpdir, zip) + Roo::ZipFile.open(@filename) do |zip_file| + if content_entry = zip_file.glob("content.xml").first + content_entry.extract(File.join(@tmpdir, 'roo_content.xml')) + else + raise ArgumentError, 'file missing required content.xml' + end end super(filename, options) @formula = Hash.new diff --git a/test/test_roo.rb b/test/test_roo.rb index 5f97e506..70fb7bdc 100644 --- a/test/test_roo.rb +++ b/test/test_roo.rb @@ -1003,7 +1003,7 @@ def test_file_warning_error def test_file_warning_warning if OPENOFFICE - assert_raises(Errno::ENOENT) { + assert_raises(ArgumentError) { Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"), packed: false, file_warning: :warning)