diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/roo/base.rb | 8 | ||||
| -rwxr-xr-x | lib/roo/excelx.rb | 12 | ||||
| -rw-r--r-- | lib/roo/excelx/cell/number.rb | 2 | ||||
| -rw-r--r-- | lib/roo/excelx/comments.rb | 2 | ||||
| -rw-r--r-- | lib/roo/formatters/csv.rb | 10 | ||||
| -rw-r--r-- | lib/roo/formatters/yaml.rb | 2 | ||||
| -rw-r--r-- | lib/roo/open_office.rb | 4 | ||||
| -rw-r--r-- | lib/roo/spreadsheet.rb | 2 | ||||
| -rw-r--r-- | lib/roo/tempdir.rb | 5 | ||||
| -rw-r--r-- | lib/roo/utils.rb | 3 | ||||
| -rw-r--r-- | lib/roo/version.rb | 2 |
11 files changed, 31 insertions, 21 deletions
diff --git a/lib/roo/base.rb b/lib/roo/base.rb index 91c8d1c..80b495e 100644 --- a/lib/roo/base.rb +++ b/lib/roo/base.rb @@ -250,10 +250,10 @@ class Roo::Base # iterate through all worksheets of a document def each_with_pagename - Enumerator.new do |yielder| - sheets.each do |s| - yielder << sheet(s, true) - end + return to_enum(:each_with_pagename) { sheets.size } unless block_given? + + sheets.each do |s| + yield sheet(s, true) end end diff --git a/lib/roo/excelx.rb b/lib/roo/excelx.rb index 91ebc1e..14a6b4f 100755 --- a/lib/roo/excelx.rb +++ b/lib/roo/excelx.rb @@ -333,7 +333,7 @@ module Roo wb = entries.find { |e| e.name[/workbook.xml$/] } fail ArgumentError 'missing required workbook file' if wb.nil? - wb.extract(path) + wb.extract(File.basename(path), destination_directory: File.dirname(path)) workbook_doc = Roo::Utils.load_xml(path).remove_namespaces! workbook_doc.xpath('//sheet').map { |s| s['id'] } end @@ -357,7 +357,7 @@ module Roo wb_rels = entries.find { |e| e.name[/workbook.xml.rels$/] } fail ArgumentError 'missing required workbook file' if wb_rels.nil? - wb_rels.extract(path) + wb_rels.extract(File.basename(path), destination_directory: File.dirname(path)) rels_doc = Roo::Utils.load_xml(path).remove_namespaces! relationships = rels_doc.xpath('//Relationship').select do |relationship| @@ -378,7 +378,7 @@ module Roo path = "#{tmpdir}/roo_sheet#{i + 1}" sheet_files << path @sheet_files << path - entry.extract(path) + entry.extract(File.basename(path), destination_directory: File.dirname(path)) end end @@ -387,7 +387,7 @@ module Roo img_entries.each do |entry| path = "#{@tmpdir}/roo#{entry.name.gsub(/xl\/|\//, "_")}" image_files << path - entry.extract(path) + entry.extract(File.basename(path), destination_directory: File.dirname(path)) end end @@ -402,7 +402,7 @@ module Roo zip_file.read_from_stream zipfilename_or_stream end - process_zipfile_entries zip_file.to_a.sort_by(&:name) + process_zipfile_entries zip_file.entries.sort_by(&:name) end def process_zipfile_entries(entries) @@ -462,7 +462,7 @@ module Roo image_rels[nr - 1] = "#{@tmpdir}/roo_image_rels#{nr}" end - entry.extract(path) if path + entry.extract(File.basename(path), destination_directory: File.dirname(path)) if path end end diff --git a/lib/roo/excelx/cell/number.rb b/lib/roo/excelx/cell/number.rb index 5cd9b55..5cdec5e 100644 --- a/lib/roo/excelx/cell/number.rb +++ b/lib/roo/excelx/cell/number.rb @@ -51,7 +51,7 @@ module Roo when /^#,##0.(0+)$/ then number_format("%.#{$1.size}f") when '0%' proc do |number| - Kernel.format('%d%%', number.to_f * 100) + Kernel.format('%.0f%%', number.to_f * 100) end when '0.00%' proc do |number| diff --git a/lib/roo/excelx/comments.rb b/lib/roo/excelx/comments.rb index 65044a9..c37097a 100644 --- a/lib/roo/excelx/comments.rb +++ b/lib/roo/excelx/comments.rb @@ -13,7 +13,7 @@ module Roo return {} unless doc_exists? doc.xpath('//comments/commentList/comment').each_with_object({}) do |comment, hash| - value = (comment.at_xpath('./text/r/t') || comment.at_xpath('./text/t')).text + value = comment.xpath('./text/r/t', './text/t').text hash[::Roo::Utils.ref_to_key(comment['ref'].to_s)] = value end end diff --git a/lib/roo/formatters/csv.rb b/lib/roo/formatters/csv.rb index 3181f09..67f63fa 100644 --- a/lib/roo/formatters/csv.rb +++ b/lib/roo/formatters/csv.rb @@ -1,7 +1,15 @@ module Roo module Formatters module CSV - def to_csv(filename = nil, separator = ",", sheet = default_sheet) + def to_csv(filename = nil, old_separator = nil, old_sheet = nil, separator: ",", sheet: default_sheet) + if old_separator + warn("[DEPRECATION] optional argument for separator is deprecated. Please use keyword argument :separator instead") + separator = old_separator + end + if old_sheet + warn("[DEPRECATION] optional argument for sheet is deprecated. Please use keyword argument :sheet instead") + sheet = old_sheet + end if filename File.open(filename, "w") do |file| write_csv_content(file, sheet, separator) diff --git a/lib/roo/formatters/yaml.rb b/lib/roo/formatters/yaml.rb index 69ef3ab..090b334 100644 --- a/lib/roo/formatters/yaml.rb +++ b/lib/roo/formatters/yaml.rb @@ -13,7 +13,7 @@ module Roo from_column ||= first_column(sheet) to_column ||= last_column(sheet) - result = "--- \n" + result = String.new("--- \n") from_row.upto(to_row) do |row| from_column.upto(to_column) do |col| next if empty?(row, col, sheet) diff --git a/lib/roo/open_office.rb b/lib/roo/open_office.rb index 542c5b4..f7a8139 100644 --- a/lib/roo/open_office.rb +++ b/lib/roo/open_office.rb @@ -59,7 +59,7 @@ module Roo fail ArgumentError, ERROR_MISSING_CONTENT_XML unless content_entry roo_content_xml_path = ::File.join(@tmpdir, 'roo_content.xml') - content_entry.extract(roo_content_xml_path) + content_entry.extract('roo_content.xml', destination_directory: @tmpdir) decrypt_if_necessary(zip_file, content_entry, roo_content_xml_path, options) end end @@ -234,7 +234,7 @@ module Roo if (manifest_entry = zip_file.glob('META-INF/manifest.xml').first) roo_manifest_xml_path = File.join(@tmpdir, 'roo_manifest.xml') - manifest_entry.extract(roo_manifest_xml_path) + manifest_entry.extract('roo_manifest.xml', destination_directory: @tmpdir) manifest = ::Roo::Utils.load_xml(roo_manifest_xml_path) # XPath search for manifest:encryption-data only for the content.xml diff --git a/lib/roo/spreadsheet.rb b/lib/roo/spreadsheet.rb index 54063b6..909dd62 100644 --- a/lib/roo/spreadsheet.rb +++ b/lib/roo/spreadsheet.rb @@ -25,7 +25,7 @@ module Roo extension.tr('.', '').downcase.to_sym else parsed_path = - if path =~ /\A#{::URI::DEFAULT_PARSER.make_regexp}\z/ + if path =~ /\A#{::Roo::Utils::URI_PARSER.make_regexp}\z/ # path is 7th match Regexp.last_match[7] else diff --git a/lib/roo/tempdir.rb b/lib/roo/tempdir.rb index 4be755b..7ad7989 100644 --- a/lib/roo/tempdir.rb +++ b/lib/roo/tempdir.rb @@ -4,7 +4,10 @@ module Roo if @tempdirs && (dirs_to_remove = @tempdirs[object_id]) @tempdirs.delete(object_id) dirs_to_remove.each do |dir| - ::FileUtils.remove_entry(dir) + # Pass force=true to avoid an exception (and thus warnings in Ruby 3.1) if dir has + # already been removed. This can occur when the finalizer is called both in a forked + # child process and in the parent. + ::FileUtils.remove_entry(dir, true) end end end diff --git a/lib/roo/utils.rb b/lib/roo/utils.rb index 2d6754a..9dcfd24 100644 --- a/lib/roo/utils.rb +++ b/lib/roo/utils.rb @@ -5,6 +5,7 @@ module Roo extend self LETTERS = ('A'..'Z').to_a + URI_PARSER = defined?(::URI::RFC2396_PARSER) ? ::URI::RFC2396_PARSER : ::URI::DEFAULT_PARSER def extract_coordinate(s) num = letter_num = 0 @@ -34,8 +35,6 @@ module Roo extract_coordinate(str) end - - def split_coord(str) coord = extract_coordinate(str) [number_to_letter(coord.column), coord.row] diff --git a/lib/roo/version.rb b/lib/roo/version.rb index 0ad4acc..3adf0b7 100644 --- a/lib/roo/version.rb +++ b/lib/roo/version.rb @@ -1,3 +1,3 @@ module Roo - VERSION = "2.10.0" + VERSION = "3.0.0" end |
