Skip to content

Commit

Permalink
Inline and simplify OpenOffice.process_zipfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Empact committed Nov 24, 2014
1 parent a74157a commit 835368e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
25 changes: 6 additions & 19 deletions lib/roo/open_office.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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={})
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_roo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 835368e

Please sign in to comment.