roo 2.10.0 → 2.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d43d60129a4ccbb82fe7438993aab2d6c0d7818be11c0dc28f96b76bdaedd960
4
- data.tar.gz: 2fce78021ad19c23a840dff9647c227a917b6537591df6c1c249c62d2045356b
3
+ metadata.gz: cd6f8267a04fcec20134f5170360fdd0259369b0c8b319100d0304c95964a6f5
4
+ data.tar.gz: 6e33716242265c9c02a7cc42b22690f03114cf12bcbbe846055040fede3cd790
5
5
  SHA512:
6
- metadata.gz: df1b92404e2835b8265c0dfded00d0fc57502e87cea3fec2798adced13bf0b4cbf04732404371ea534071740cc60f4db2b6f5c110da8006d44ad41fc47b4d728
7
- data.tar.gz: b6062d76dafda4cd64870ef100803e61ac8e32f565a5f3a0ffafee7a674e7dfada71e6e243fe7f37545efb7457be99a39a5c035498df85a8dbd02151dffca593
6
+ metadata.gz: 65dd59afe1dfda800c7e88547f305dbd1eb295c5715fd23dc5123618307205ae1a0c0740511739d2880b4d91cabca10fad152d522cca96a2694f8e3c1cccbd39
7
+ data.tar.gz: 9d239b22ee226fc3466d2445127dc2c4fc50c488249171b0b86dc17a4a41779e543e83ed3def1fe9fae26ddc67608a81733483e3757b32156d822abdbf2bc974
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
- ## Unreleased
1
+ ## [2.10.1] 2024-01-17
2
2
 
3
3
  ### Changed/Added
4
+ - Prevent warnings on Ruby 3.1 if finalizer is called twice [586](https://github.com/roo-rb/roo/pull/586)
5
+ - Fix Roo::Base#each_with_pagename degraded at [576](https://github.com/roo-rb/roo/pull/576) [583](https://github.com/roo-rb/roo/pull/583)
4
6
 
5
7
  ## [2.10.0] 2023-02-07
6
8
 
data/README.md CHANGED
@@ -22,22 +22,37 @@ gem "roo", "~> 2.10.0"
22
22
  ```
23
23
  ## Usage
24
24
 
25
- Opening a spreadsheet
25
+ ### Opening a spreadsheet
26
26
 
27
+ You can use the `Roo::Spreadsheet` class so `roo` automatically detects which [parser class](https://github.com/roo-rb/roo/blob/master/lib/roo.rb#L17) to use for you.
27
28
  ```ruby
28
29
  require 'roo'
29
30
 
30
- xlsx = Roo::Spreadsheet.open('./new_prices.xlsx')
31
- xlsx = Roo::Excelx.new("./new_prices.xlsx")
31
+ file_name = './new_prices.xlsx'
32
+ xlsx = Roo::Spreadsheet.open(file_name)
33
+ xlsx.info
34
+ # => Returns basic info about the spreadsheet file
35
+ ```
32
36
 
33
- # Use the extension option if the extension is ambiguous.
34
- xlsx = Roo::Spreadsheet.open('./rails_temp_upload', extension: :xlsx)
37
+ ``Roo::Spreadsheet.open`` can accept both string paths and ``File`` instances. Also, you can provide the extension of the file as an option:
38
+
39
+ ```ruby
40
+ require 'roo'
35
41
 
42
+ file_name = './rails_temp_upload'
43
+ xlsx = Roo::Spreadsheet.open(file_name, extension: :xlsx)
36
44
  xlsx.info
37
45
  # => Returns basic info about the spreadsheet file
38
46
  ```
39
47
 
40
- ``Roo::Spreadsheet.open`` can accept both paths and ``File`` instances.
48
+ On the other hand, if you know what the file extension is, you can use the specific parser class instead:
49
+ ```ruby
50
+ require 'roo'
51
+
52
+ xlsx = Roo::Excelx.new("./new_prices.xlsx")
53
+ xlsx.info
54
+ # => Returns basic info about the spreadsheet file
55
+ ```
41
56
 
42
57
  ### Working with sheets
43
58
 
data/lib/roo/base.rb CHANGED
@@ -250,10 +250,10 @@ class Roo::Base
250
250
 
251
251
  # iterate through all worksheets of a document
252
252
  def each_with_pagename
253
- Enumerator.new do |yielder|
254
- sheets.each do |s|
255
- yielder << sheet(s, true)
256
- end
253
+ return to_enum(:each_with_pagename) { sheets.size } unless block_given?
254
+
255
+ sheets.each do |s|
256
+ yield sheet(s, true)
257
257
  end
258
258
  end
259
259
 
@@ -51,7 +51,7 @@ module Roo
51
51
  when /^#,##0.(0+)$/ then number_format("%.#{$1.size}f")
52
52
  when '0%'
53
53
  proc do |number|
54
- Kernel.format('%d%%', number.to_f * 100)
54
+ Kernel.format('%.0f%%', number.to_f * 100)
55
55
  end
56
56
  when '0.00%'
57
57
  proc do |number|
data/lib/roo/tempdir.rb CHANGED
@@ -4,7 +4,10 @@ module Roo
4
4
  if @tempdirs && (dirs_to_remove = @tempdirs[object_id])
5
5
  @tempdirs.delete(object_id)
6
6
  dirs_to_remove.each do |dir|
7
- ::FileUtils.remove_entry(dir)
7
+ # Pass force=true to avoid an exception (and thus warnings in Ruby 3.1) if dir has
8
+ # already been removed. This can occur when the finalizer is called both in a forked
9
+ # child process and in the parent.
10
+ ::FileUtils.remove_entry(dir, true)
8
11
  end
9
12
  end
10
13
  end
data/lib/roo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Roo
2
- VERSION = "2.10.0"
2
+ VERSION = "2.10.1"
3
3
  end
@@ -183,10 +183,22 @@ describe Roo::Base do
183
183
  end
184
184
 
185
185
  describe '#each_with_pagename' do
186
- it 'should return an enumerator with all the rows' do
187
- each_with_pagename = spreadsheet.each_with_pagename
188
- expect(each_with_pagename).to be_a(Enumerator)
189
- expect(each_with_pagename.to_a.last).to eq([spreadsheet.default_sheet, spreadsheet])
186
+ context 'when block given' do
187
+ it 'iterate with sheet and sheet_name' do
188
+ sheet_names = []
189
+ spreadsheet.each_with_pagename do |sheet_name, sheet|
190
+ sheet_names << sheet_name
191
+ end
192
+ expect(sheet_names).to eq ['my_sheet', 'blank sheet']
193
+ end
194
+ end
195
+
196
+ context 'when called without block' do
197
+ it 'should return an enumerator with all the rows' do
198
+ each_with_pagename = spreadsheet.each_with_pagename
199
+ expect(each_with_pagename).to be_a(Enumerator)
200
+ expect(each_with_pagename.to_a.last).to eq([spreadsheet.default_sheet, spreadsheet])
201
+ end
190
202
  end
191
203
  end
192
204
 
@@ -35,6 +35,11 @@ class TestRooExcelxCellNumber < Minitest::Test
35
35
  assert_kind_of(Float, cell.value)
36
36
  end
37
37
 
38
+ def test_rounded_percent_formatted_value
39
+ cell = Roo::Excelx::Cell::Number.new '0.569999999995', nil, ['0%'], nil, nil, nil
40
+ assert_equal('57%', cell.formatted_value)
41
+ end
42
+
38
43
  def test_formats_with_negative_numbers
39
44
  [
40
45
  ['#,##0 ;(#,##0)', '(1,042)'],
@@ -36,6 +36,27 @@ module TestAccesingFiles
36
36
  end
37
37
  end
38
38
 
39
+ def test_finalize_twice
40
+ skip if defined? JRUBY_VERSION
41
+
42
+ instance = Class.new { include Roo::Tempdir }.new
43
+
44
+ tempdir = instance.make_tempdir(instance, "my_temp_prefix", nil)
45
+ assert File.exist?(tempdir), "Expected #{tempdir} to initially exist"
46
+
47
+ pid = Process.fork do
48
+ # Inside the forked process finalize does not affect the parent process's state, but does
49
+ # delete the tempfile on disk
50
+ instance.finalize_tempdirs(instance.object_id)
51
+ end
52
+
53
+ Process.wait(pid)
54
+ refute File.exist?(tempdir), "Expected #{tempdir} to have been cleaned up by child process"
55
+
56
+ instance.finalize_tempdirs(instance.object_id)
57
+ refute File.exist?(tempdir), "Expected #{tempdir} to still have been cleaned up"
58
+ end
59
+
39
60
  def test_cleanup_on_error
40
61
  # NOTE: This test was occasionally failing because when it started running
41
62
  # other tests would have already added folders to the temp directory,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Preymesser
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2023-02-07 00:00:00.000000000 Z
16
+ date: 2024-01-18 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: nokogiri
@@ -256,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
256
  - !ruby/object:Gem::Version
257
257
  version: '0'
258
258
  requirements: []
259
- rubygems_version: 3.4.2
259
+ rubygems_version: 3.3.26
260
260
  signing_key:
261
261
  specification_version: 4
262
262
  summary: Roo can access the contents of various spreadsheet files.