summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGeremia Taglialatela <[email protected]>2023-05-27 12:33:34 +0200
committerGeremia Taglialatela <[email protected]>2023-05-27 12:33:34 +0200
commit171f4ad7d68f8b9e93fa9e65b31bf313d8c57296 (patch)
tree7779ef54463646fa924d3408f14e8b5deecc348d
parent63a6edf1e191cf91fb80717ebae67c78af0d7db5 (diff)
downloadcaxlsx-171f4ad7d68f8b9e93fa9e65b31bf313d8c57296.tar.gz
caxlsx-171f4ad7d68f8b9e93fa9e65b31bf313d8c57296.zip
Improve absolute cell reference method
Also inverts `string.match(REGEX)` with `REGEX.match(string)` because of uniformity and because it has been tested 5% more performant on Ruby 3.2. Performance on older Rubies is the same ``` REGEX.match(string): 1234330.7 i/s string.match(REGEX): 1172670.1 i/s - 1.05x (± 0.00) slower ```
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 09cf2064..b4f826c2 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -73,6 +73,9 @@ module Axlsx
CELL_TYPES = [:date, :time, :float, :integer, :richtext,
:string, :boolean, :iso_8601, :text].freeze
+ # A regular expression to match the alpha(column)numeric(row) reference of a cell
+ CELL_REFERENCE_REGEX = /([A-Z]+)([0-9]+)/.freeze
+
# The index of the cellXfs item to be applied to this cell.
# @return [Integer]
# @see Axlsx::Styles
@@ -345,11 +348,11 @@ module Axlsx
Axlsx::cell_r index, @row.row_index
end
- # @return [String] The absolute alpha(column)numeric(row) reference for this sell.
+ # @return [String] The absolute alpha(column)numeric(row) reference for this cell.
# @example Absolute Cell Reference
# ws.rows.first.cells.first.r #=> "$A$1"
def r_abs
- "$#{r.match(/([A-Z]+)([0-9]+)/)[1, 2].join('$')}"
+ "$#{CELL_REFERENCE_REGEX.match(r)[1, 2].join('$')}"
end
# @return [Integer] The cellXfs item index applied to this cell.