lib/roo/excelx.rb in roo-2.6.0 vs lib/roo/excelx.rb in roo-2.7.0
- old
+ new
@@ -2,16 +2,15 @@
require 'zip/filesystem'
require 'roo/link'
require 'roo/tempdir'
require 'roo/utils'
require 'forwardable'
+require 'set'
module Roo
class Excelx < Roo::Base
extend Roo::Tempdir
-
- require 'set'
extend Forwardable
ERROR_VALUES = %w(#N/A #REF! #NAME? #DIV/0! #NULL! #VALUE! #NUM!).to_set
require 'roo/excelx/shared'
@@ -44,11 +43,17 @@
unless is_stream?(filename_or_stream)
file_type_check(filename_or_stream, %w[.xlsx .xlsm], 'an Excel 2007', file_warning, packed)
basename = find_basename(filename_or_stream)
end
+ # NOTE: Create temp directory and allow Ruby to cleanup the temp directory
+ # when the object is garbage collected. Initially, the finalizer was
+ # created in the Roo::Tempdir module, but that led to a segfault
+ # when testing in Ruby 2.4.0.
@tmpdir = self.class.make_tempdir(self, basename, options[:tmpdir_root])
+ ObjectSpace.define_finalizer(self, self.class.finalize(object_id))
+
@shared = Shared.new(@tmpdir)
@filename = local_filename(filename_or_stream, @tmpdir, packed)
process_zipfile(@filename || filename_or_stream)
@sheet_names = workbook.sheets.map do |sheet|
@@ -216,10 +221,10 @@
def empty?(row, col, sheet = nil)
sheet = sheet_for(sheet)
key = normalize(row, col)
cell = sheet.cells[key]
- !cell || cell.empty? || (cell.type == :string && cell.value.empty?) ||
+ !cell || cell.empty? ||
(row < sheet.first_row || row > sheet.last_row || col < sheet.first_column || col > sheet.last_column)
end
# shows the internal representation of all cells
# for debugging purposes