roo 2.8.0 → 2.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b99744522c3a62e004d42498388c4e99cdb2d45157fc26b87eb54023a957452f
4
- data.tar.gz: ab4445f118a1144c71142a2c28724686da05d28ce04a04c0746c49628834d132
3
+ metadata.gz: 1e41bf12228c4a168e8df0a0cbf5b94eceaa89a1f5d174f3a3588a1a965d49f4
4
+ data.tar.gz: 69d749c2667ba4efbdcd7257550ba380d6ba0250633d439ae738673e6d2b5924
5
5
  SHA512:
6
- metadata.gz: 9bc47d73a1556e7b82b652379bcba4940f9982814286feb626097e9ddea0f3a021c7ca7e9d8399293248df5272ac8db0b39c896abd940a759683ce09260e77e2
7
- data.tar.gz: 69baf682a05fa581756a92a270e6bd44431f36683d9f1104d0466f8452201d32a34cf6a626b8168d6ef022bb2ed6b0d932e2ff5a3b1c2367c02fd4f224ce8eeb
6
+ metadata.gz: 14c8d1e69b31e1be16c8845c686e596c108e9c4251e4d5ee75471dd8ea325c2aacdcf1fa4b10f6262cd840bd063de5b11432439a9bce1b82b4c350566981bb48
7
+ data.tar.gz: 7a01fefbe77485af0252384dcd20770e0c993c29b916be55736a86fcdc8de710d99709fb09d95f4d628a2b3819069c3aba5df28f3488a5f519753b854c82cd48
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## Unreleased
2
+
3
+ ## [2.8.3] 2020-02-03
4
+ ### Changed/Added
5
+ - Updated rubyzip version. Now minimal version is 1.3.0 [515](https://github.com/roo-rb/roo/pull/515) - [CVE-2019-16892](https://github.com/rubyzip/rubyzip/pull/403)
6
+
7
+ ## [2.8.2] 2019-02-01
8
+ ### Changed/Added
9
+ - Support range cell for Excelx's links [490](https://github.com/roo-rb/roo/pull/490)
10
+ - Skip `extract_hyperlinks` if not required [488](https://github.com/roo-rb/roo/pull/488)
11
+
12
+ ### Fixed
13
+ - Fixed error for invalid link [492](https://github.com/roo-rb/roo/pull/492)
14
+
15
+ ## [2.8.1] 2019-01-21
16
+ ### Fixed
17
+ - Fixed error if excelx's cell have empty children [487](https://github.com/roo-rb/roo/pull/487)
18
+
1
19
  ## [2.8.0] 2019-01-18
2
20
  ### Fixed
3
21
  - Fixed inconsistent column length for CSV [375](https://github.com/roo-rb/roo/pull/375)
data/README.md CHANGED
@@ -18,7 +18,7 @@ Install as a gem
18
18
  Or add it to your Gemfile
19
19
 
20
20
  ```ruby
21
- gem "roo", "~> 2.7.0"
21
+ gem "roo", "~> 2.8.0"
22
22
  ```
23
23
  ## Usage
24
24
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'roo/excelx/extractor'
2
4
 
3
5
  module Roo
@@ -11,10 +13,16 @@ module Roo
11
13
  @relationships ||= extract_relationships
12
14
  end
13
15
 
16
+ def include_type?(type)
17
+ to_a.any? do |_, rel|
18
+ rel["Type"]&.include? type
19
+ end
20
+ end
21
+
14
22
  private
15
23
 
16
24
  def extract_relationships
17
- return [] unless doc_exists?
25
+ return {} unless doc_exists?
18
26
 
19
27
  doc.xpath('/Relationships/Relationship').each_with_object({}) do |rel, hash|
20
28
  hash[rel['Id']] = rel
@@ -22,7 +22,7 @@ module Roo
22
22
 
23
23
  def hyperlinks(relationships)
24
24
  # If you're sure you're not going to need this hyperlinks you can discard it
25
- @hyperlinks ||= if @options[:no_hyperlinks]
25
+ @hyperlinks ||= if @options[:no_hyperlinks] || !relationships.include_type?("hyperlink")
26
26
  {}
27
27
  else
28
28
  extract_hyperlinks(relationships)
@@ -120,7 +120,7 @@ module Roo
120
120
  end
121
121
  end
122
122
 
123
- create_empty_cell(coordinate)
123
+ create_empty_cell(coordinate, empty_cell)
124
124
  end
125
125
 
126
126
  def create_empty_cell(coordinate, empty_cell)
@@ -185,7 +185,10 @@ module Roo
185
185
  if relationship = relationships[hyperlink['id']]
186
186
  target_link = relationship['Target']
187
187
  target_link += "##{hyperlink['location']}" if hyperlink['location']
188
- hash[::Roo::Utils.ref_to_key(hyperlink["ref"].to_s)] = target_link
188
+
189
+ Roo::Utils.coordinates_in_range(hyperlink["ref"].to_s) do |coord|
190
+ hash[coord] = target_link
191
+ end
189
192
  end
190
193
  end
191
194
  end
data/lib/roo/utils.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Roo
2
4
  module Utils
3
5
  extend self
@@ -41,7 +43,7 @@ module Roo
41
43
 
42
44
  # convert a number to something like 'AB' (1 => 'A', 2 => 'B', ...)
43
45
  def number_to_letter(num)
44
- result = ""
46
+ result = +""
45
47
 
46
48
  until num.zero?
47
49
  num, index = (num - 1).divmod(26)
@@ -73,6 +75,25 @@ module Roo
73
75
  (x2 - (x1 - 1)) * (y2 - (y1 - 1))
74
76
  end
75
77
 
78
+ def coordinates_in_range(str)
79
+ return to_enum(:coordinates_in_range, str) unless block_given?
80
+ coordinates = str.split(":", 2).map! { |s| extract_coordinate s }
81
+
82
+ case coordinates.size
83
+ when 1
84
+ yield coordinates[0]
85
+ when 2
86
+ tl, br = coordinates
87
+ rows = tl.row..br.row
88
+ cols = tl.column..br.column
89
+ rows.each do |row|
90
+ cols.each do |column|
91
+ yield Excelx::Coordinate.new(row, column)
92
+ end
93
+ end
94
+ end
95
+ end
96
+
76
97
  def load_xml(path)
77
98
  ::File.open(path, 'rb') do |file|
78
99
  ::Nokogiri::XML(file)
data/lib/roo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Roo
2
- VERSION = "2.8.0"
2
+ VERSION = "2.8.3"
3
3
  end
data/roo.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.required_ruby_version = ">= 2.3.0"
21
21
 
22
22
  spec.add_dependency 'nokogiri', '~> 1'
23
- spec.add_dependency 'rubyzip', '>= 1.2.1', '< 2.0.0'
23
+ spec.add_dependency 'rubyzip', '>= 1.3.0', '< 3.0.0'
24
24
 
25
25
  spec.add_development_dependency 'rake', '~> 10.1'
26
26
  spec.add_development_dependency 'minitest', '~> 5.4', '>= 5.4.3'
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ describe Roo::Excelx::Relationships do
6
+ subject(:relationships) { Roo::Excelx::Relationships.new Roo::Excelx.new(path).rels_files[0] }
7
+
8
+ describe "#include_type?" do
9
+ [
10
+ ["with hyperlink type", "test/files/link.xlsx", true, false],
11
+ ["with nil path", "test/files/Bibelbund.xlsx", false, false],
12
+ ["with comments type", "test/files/comments-google.xlsx", false, true],
13
+ ].each do |context_desc, file_path, hyperlink_value, comments_value|
14
+ context context_desc do
15
+ let(:path) { file_path }
16
+
17
+ it "should return #{hyperlink_value} for hyperlink" do
18
+ expect(subject.include_type?("hyperlink")).to be hyperlink_value
19
+ end
20
+
21
+ it "should return #{hyperlink_value} for link" do
22
+ expect(subject.include_type?("link")).to be hyperlink_value
23
+ end
24
+
25
+ it "should return false for hypelink" do
26
+ expect(subject.include_type?("hypelink")).to be false
27
+ end
28
+
29
+ it "should return false for coment" do
30
+ expect(subject.include_type?("coment")).to be false
31
+ end
32
+
33
+ it "should return #{comments_value} for comments" do
34
+ expect(subject.include_type?("comments")).to be comments_value
35
+ end
36
+
37
+ it "should return #{comments_value} for comment" do
38
+ expect(subject.include_type?("comment")).to be comments_value
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ describe Roo::Excelx::SheetDoc do
6
+ subject(:blank_children) { Roo::Excelx.new("test/files/blank_children.xlsx") }
7
+
8
+ example "#last_row" do
9
+ expect(subject.last_row).to eq 3
10
+ end
11
+ end
@@ -379,9 +379,34 @@ describe Roo::Excelx do
379
379
  expect(subject.hyperlink?(1, 1)).to eq true
380
380
  expect(subject.hyperlink?(1, 2)).to eq false
381
381
  end
382
+
383
+ context 'defined on cell range' do
384
+ let(:path) { 'test/files/cell-range-link.xlsx' }
385
+
386
+ it 'returns the expected result' do
387
+ [[false]*3, *[[true, true, false]]*4, [false]*3].each.with_index(1) do |row, row_index|
388
+ row.each.with_index(1) do |value, col_index|
389
+ expect(subject.hyperlink?(row_index, col_index)).to eq(value)
390
+ end
391
+ end
392
+ end
393
+ end
382
394
  end
383
395
 
384
396
  describe '#hyperlink' do
397
+ context 'defined on cell range' do
398
+ let(:path) { 'test/files/cell-range-link.xlsx' }
399
+
400
+ it 'returns the expected result' do
401
+ link = "http://www.google.com"
402
+ [[nil]*3, *[[link, link, nil]]*4, [nil]*3].each.with_index(1) do |row, row_index|
403
+ row.each.with_index(1) do |value, col_index|
404
+ expect(subject.hyperlink(row_index, col_index)).to eq(value)
405
+ end
406
+ end
407
+ end
408
+ end
409
+
385
410
  context 'without location' do
386
411
  let(:path) { 'test/files/link.xlsx' }
387
412
 
@@ -90,6 +90,19 @@ RSpec.describe ::Roo::Utils do
90
90
  end
91
91
  end
92
92
 
93
+ context '.coordinates_in_range' do
94
+ it "returns the expected result" do
95
+ expect(described_class.coordinates_in_range('').to_a).to eq []
96
+ expect(described_class.coordinates_in_range('B2').to_a).to eq [[2, 2]]
97
+ expect(described_class.coordinates_in_range('D2:G3').to_a).to eq [[2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7]]
98
+ expect(described_class.coordinates_in_range('G3:D2').to_a).to eq []
99
+ end
100
+
101
+ it "raises an error when appropriate" do
102
+ expect { described_class.coordinates_in_range('D2:G3:I5').to_a }.to raise_error(ArgumentError)
103
+ end
104
+ end
105
+
93
106
  context '.load_xml' do
94
107
  it 'returns the expected result' do
95
108
  expect(described_class.load_xml('test/files/sheet1.xml')).to be_a(Nokogiri::XML::Document)
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class TestRworkbookExcelx < Minitest::Test
4
4
  def test_download_uri_with_invalid_host
5
5
  assert_raises(RuntimeError) do
6
- Roo::Excelx.new("http://example.com/file.xlsx")
6
+ Roo::Excelx.new("http://examples.com/file.xlsx")
7
7
  end
8
8
  end
9
9
 
@@ -302,6 +302,11 @@ class TestRworkbookExcelx < Minitest::Test
302
302
  end
303
303
  end
304
304
 
305
+ def test_handles_link_without_hyperlink
306
+ workbook = Roo::Spreadsheet.open(File.join(TESTDIR, "bad_link.xlsx"))
307
+ assert_equal "Test", workbook.cell(1, 1)
308
+ end
309
+
305
310
  # Excel has two base date formats one from 1900 and the other from 1904.
306
311
  # see #test_base_dates_in_excel
307
312
  def test_base_dates_in_excelx
@@ -15,7 +15,7 @@ class TestRooOpenOffice < Minitest::Test
15
15
 
16
16
  def test_download_uri_with_invalid_host
17
17
  assert_raises(RuntimeError) do
18
- roo_class.new("http://example.com/file.ods")
18
+ roo_class.new("http://examples.com/file.ods")
19
19
  end
20
20
  end
21
21
 
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.8.0
4
+ version: 2.8.3
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: 2019-01-18 00:00:00.000000000 Z
16
+ date: 2020-02-03 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: nokogiri
@@ -35,20 +35,20 @@ dependencies:
35
35
  requirements:
36
36
  - - ">="
37
37
  - !ruby/object:Gem::Version
38
- version: 1.2.1
38
+ version: 1.3.0
39
39
  - - "<"
40
40
  - !ruby/object:Gem::Version
41
- version: 2.0.0
41
+ version: 3.0.0
42
42
  type: :runtime
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 1.2.1
48
+ version: 1.3.0
49
49
  - - "<"
50
50
  - !ruby/object:Gem::Version
51
- version: 2.0.0
51
+ version: 3.0.0
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: rake
54
54
  requirement: !ruby/object:Gem::Requirement
@@ -182,6 +182,8 @@ files:
182
182
  - spec/lib/roo/base_spec.rb
183
183
  - spec/lib/roo/csv_spec.rb
184
184
  - spec/lib/roo/excelx/format_spec.rb
185
+ - spec/lib/roo/excelx/relationships_spec.rb
186
+ - spec/lib/roo/excelx/sheet_doc_spec.rb
185
187
  - spec/lib/roo/excelx_spec.rb
186
188
  - spec/lib/roo/libreoffice_spec.rb
187
189
  - spec/lib/roo/openoffice_spec.rb
@@ -238,8 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
240
  - !ruby/object:Gem::Version
239
241
  version: '0'
240
242
  requirements: []
241
- rubyforge_project:
242
- rubygems_version: 2.7.7
243
+ rubygems_version: 3.0.6
243
244
  signing_key:
244
245
  specification_version: 4
245
246
  summary: Roo can access the contents of various spreadsheet files.