roo 2.8.1 → 2.8.2

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: 62db88823f6fadaa7e33bbc16a68f3ed67f85d7676cbc51340d48c6867622187
4
- data.tar.gz: ada9c23708c44a4c97e145918022170fd425f0a651e56b1748be2c258f41fe26
3
+ metadata.gz: a37f2ce32f1bfc19bdb5af4016f5bda177037047c0924e207489214dd9b2988a
4
+ data.tar.gz: b803f2d67944137e95e4c703853018397f7c3188354cec3c8447ccc2d040816d
5
5
  SHA512:
6
- metadata.gz: ebb7cc89869d46e4bbf36166c00d86462878e1c54676a1439537f1499ed4c388254e4c1b89197487a96e3905f89cf601e6e3b8f7c0db977844b478de8938d58a
7
- data.tar.gz: 885465f444f35ffd2ce68e0963d87ab1457234df91c16012d60d58f38f0eda6ad0822867fe44623921f8c0184465c1477f4484c80183b692f0106ecc235cd8e1
6
+ metadata.gz: 33338f3c847a1d6ea293bdeb87be3401835027efb521c468b8471b1065b4d8bd2ec14a1ba1719e2974c321c3193eadffee0a3b37e4afbf6b8955a29dc7651f39
7
+ data.tar.gz: d40ff41b78de4f6ef8fba9cfcf464a6d25735f5f1ead8e1b724415c7018ac9058a55db65c1e174826e654b808364a33508e16a68d0099417070a4a05415e57e7
@@ -1,5 +1,13 @@
1
1
  ## Unreleased
2
2
 
3
+ ## [2.8.2] 2019-02-01
4
+ ### Changed/Added
5
+ - Support range cell for Excelx's links [490](https://github.com/roo-rb/roo/pull/490)
6
+ - Skip `extract_hyperlinks` if not required [488](https://github.com/roo-rb/roo/pull/488)
7
+
8
+ ### Fixed
9
+ - Fixed error for invalid link [492](https://github.com/roo-rb/roo/pull/492)
10
+
3
11
  ## [2.8.1] 2019-01-21
4
12
  ### Fixed
5
13
  - Fixed error if excelx's cell have empty children [487](https://github.com/roo-rb/roo/pull/487)
@@ -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)
@@ -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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Roo
2
- VERSION = "2.8.1"
2
+ VERSION = "2.8.2"
3
3
  end
@@ -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
@@ -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)
@@ -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
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.1
4
+ version: 2.8.2
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-21 00:00:00.000000000 Z
16
+ date: 2019-02-01 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: nokogiri
@@ -182,6 +182,7 @@ 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
185
186
  - spec/lib/roo/excelx/sheet_doc_spec.rb
186
187
  - spec/lib/roo/excelx_spec.rb
187
188
  - spec/lib/roo/libreoffice_spec.rb