summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/workbook.rb
diff options
context:
space:
mode:
authorGeremia Taglialatela <[email protected]>2023-05-15 22:12:05 +0200
committerGeremia Taglialatela <[email protected]>2023-05-15 22:12:05 +0200
commita0bef85fc877afe91e22558bac5e14e2f7f88dbe (patch)
tree3c1225284ddf8f26c94a48303734dd8ec811db87 /lib/axlsx/workbook/workbook.rb
parent3b9ac17d8e4dc8b315ac307ffad6f2aa0cb96741 (diff)
downloadcaxlsx-a0bef85fc877afe91e22558bac5e14e2f7f88dbe.tar.gz
caxlsx-a0bef85fc877afe91e22558bac5e14e2f7f88dbe.zip
Use `include?` and `find` for performance
Fix a couple of performance RuboCop offenses in workbook
Diffstat (limited to 'lib/axlsx/workbook/workbook.rb')
-rw-r--r--lib/axlsx/workbook/workbook.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index 3e4927aa..1a2f0488 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -395,8 +395,8 @@ module Axlsx
# retrieve the cells from. e.g. range('Sheet1!A1:B2') will return an array of four cells [A1, A2, B1, B2] while range('Sheet1!A1') will return a single Cell.
# @return [Cell, Array]
def [](cell_def)
- sheet_name = cell_def.split('!')[0] if cell_def.match('!')
- worksheet = self.worksheets.select { |s| s.name == sheet_name }.first
+ sheet_name = cell_def.split('!')[0] if cell_def.include?('!')
+ worksheet = self.worksheets.find { |s| s.name == sheet_name }
raise ArgumentError, 'Unknown Sheet' unless sheet_name && worksheet.is_a?(Worksheet)
worksheet[cell_def.gsub(/.+!/, "")]