summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGeremia Taglialatela <[email protected]>2023-06-05 16:49:23 +0200
committerGeremia Taglialatela <[email protected]>2023-06-05 17:27:41 +0200
commit0cc60e3eb08e11542612871e2e15350ed07fff06 (patch)
treeae63495552175e26ab6be3aefe190a7e5ab657a9
parent7fdbd745a2c914001a2174aeadae26b9c970ffaf (diff)
downloadcaxlsx-0cc60e3eb08e11542612871e2e15350ed07fff06.tar.gz
caxlsx-0cc60e3eb08e11542612871e2e15350ed07fff06.zip
Fix Style/RedundantInterpolation offenses
`%` is an operation on `String` that will return a new `String`, so the interpolation is redundant Also adds a missing spec on PivotTable#rels_pn ``` IPS: uninterpolated: 4045715.7 i/s interpolated: 2359775.6 i/s - 1.71x (± 0.00) slower Memory: uninterpolated: 160 allocated interpolated: 232 allocated - 1.45x more ```
-rw-r--r--.rubocop_todo.yml13
-rw-r--r--lib/axlsx/drawing/chart.rb2
-rw-r--r--lib/axlsx/drawing/drawing.rb4
-rw-r--r--lib/axlsx/drawing/pic.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/comments.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/table.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb4
-rw-r--r--test/workbook/worksheet/tc_pivot_table.rb6
10 files changed, 17 insertions, 24 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 67e59726..b68f9b61 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -323,19 +323,6 @@ Style/RandomWithOffset:
Exclude:
- 'lib/axlsx/drawing/vml_shape.rb'
-# This cop supports unsafe autocorrection (--autocorrect-all).
-Style/RedundantInterpolation:
- Exclude:
- - 'lib/axlsx/drawing/chart.rb'
- - 'lib/axlsx/drawing/drawing.rb'
- - 'lib/axlsx/drawing/pic.rb'
- - 'lib/axlsx/drawing/vml_drawing.rb'
- - 'lib/axlsx/workbook/worksheet/comments.rb'
- - 'lib/axlsx/workbook/worksheet/pivot_table.rb'
- - 'lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb'
- - 'lib/axlsx/workbook/worksheet/table.rb'
- - 'lib/axlsx/workbook/worksheet/worksheet.rb'
-
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantRegexpEscape:
Exclude:
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index 9f59dc6a..6b3acab1 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -124,7 +124,7 @@ module Axlsx
# The part name for this chart
# @return [String]
def pn
- "#{CHART_PN % (index + 1)}"
+ CHART_PN % (index + 1)
end
# The title object for the chart.
diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb
index fa7a608c..8ae4ed0c 100644
--- a/lib/axlsx/drawing/drawing.rb
+++ b/lib/axlsx/drawing/drawing.rb
@@ -128,14 +128,14 @@ module Axlsx
# The part name for this drawing
# @return [String]
def pn
- "#{DRAWING_PN % (index + 1)}"
+ DRAWING_PN % (index + 1)
end
# The relational part name for this drawing
# #NOTE This should be rewritten to return an Axlsx::Relationship object.
# @return [String]
def rels_pn
- "#{DRAWING_RELS_PN % (index + 1)}"
+ DRAWING_RELS_PN % (index + 1)
end
# A list of objects this drawing holds.
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb
index c9efb378..08beb2d9 100644
--- a/lib/axlsx/drawing/pic.rb
+++ b/lib/axlsx/drawing/pic.rb
@@ -131,7 +131,7 @@ module Axlsx
# @return [Relationship]
def relationship
if remote?
- Relationship.new(self, IMAGE_R, "#{image_src}", target_mode: :External)
+ Relationship.new(self, IMAGE_R, image_src.to_s, target_mode: :External)
else
Relationship.new(self, IMAGE_R, "../#{pn}")
end
diff --git a/lib/axlsx/workbook/worksheet/comments.rb b/lib/axlsx/workbook/worksheet/comments.rb
index cb8efdaa..b27a1940 100644
--- a/lib/axlsx/workbook/worksheet/comments.rb
+++ b/lib/axlsx/workbook/worksheet/comments.rb
@@ -20,7 +20,7 @@ module Axlsx
# The part name for this object
# @return [String]
def pn
- "#{COMMENT_PN % (index + 1)}"
+ COMMENT_PN % (index + 1)
end
# Creates a new Comments object
diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb
index aca3ccb5..00ffe92d 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table.rb
@@ -159,13 +159,13 @@ module Axlsx
# The part name for this table
# @return [String]
def pn
- "#{PIVOT_TABLE_PN % (index + 1)}"
+ PIVOT_TABLE_PN % (index + 1)
end
# The relationship part name of this pivot table
# @return [String]
def rels_pn
- "#{PIVOT_TABLE_RELS_PN % (index + 1)}"
+ PIVOT_TABLE_RELS_PN % (index + 1)
end
# The cache_definition for this pivot table
diff --git a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
index 4928d5ac..5bb946a0 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
@@ -26,7 +26,7 @@ module Axlsx
# The part name for this table
# @return [String]
def pn
- "#{PIVOT_TABLE_CACHE_DEFINITION_PN % (index + 1)}"
+ PIVOT_TABLE_CACHE_DEFINITION_PN % (index + 1)
end
# The identifier for this cache
diff --git a/lib/axlsx/workbook/worksheet/table.rb b/lib/axlsx/workbook/worksheet/table.rb
index 210833e0..4221925d 100644
--- a/lib/axlsx/workbook/worksheet/table.rb
+++ b/lib/axlsx/workbook/worksheet/table.rb
@@ -44,7 +44,7 @@ module Axlsx
# The part name for this table
# @return [String]
def pn
- "#{TABLE_PN % (index + 1)}"
+ TABLE_PN % (index + 1)
end
# The relationship id for this table.
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 07221b3f..d4840050 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -345,13 +345,13 @@ module Axlsx
# The part name of this worksheet
# @return [String]
def pn
- "#{WORKSHEET_PN % (index + 1)}"
+ WORKSHEET_PN % (index + 1)
end
# The relationship part name of this worksheet
# @return [String]
def rels_pn
- "#{WORKSHEET_RELS_PN % (index + 1)}"
+ WORKSHEET_RELS_PN % (index + 1)
end
# The relationship id of this worksheet.
diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb
index 606982db..d4db9cef 100644
--- a/test/workbook/worksheet/tc_pivot_table.rb
+++ b/test/workbook/worksheet/tc_pivot_table.rb
@@ -144,6 +144,12 @@ class TestPivotTable < Test::Unit::TestCase
assert_equal(2, @ws.relationships.size, "adding a pivot table adds a relationship")
end
+ def test_rels_pn
+ @ws.add_pivot_table('G5:G6', 'A1:D5')
+
+ assert_equal("pivotTables/_rels/pivotTable1.xml.rels", @ws.pivot_tables.first.rels_pn)
+ end
+
def test_to_xml_string
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', { no_subtotals_on_headers: ['Year'] }) do |pt|
pt.rows = ['Year', 'Month']