diff options
| author | Geremia Taglialatela <[email protected]> | 2023-05-15 22:12:05 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-05-15 22:12:05 +0200 |
| commit | a0bef85fc877afe91e22558bac5e14e2f7f88dbe (patch) | |
| tree | 3c1225284ddf8f26c94a48303734dd8ec811db87 | |
| parent | 3b9ac17d8e4dc8b315ac307ffad6f2aa0cb96741 (diff) | |
| download | caxlsx-a0bef85fc877afe91e22558bac5e14e2f7f88dbe.tar.gz caxlsx-a0bef85fc877afe91e22558bac5e14e2f7f88dbe.zip | |
Use `include?` and `find` for performance
Fix a couple of performance RuboCop offenses in workbook
| -rw-r--r-- | .rubocop_todo.yml | 7 | ||||
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 4 |
2 files changed, 2 insertions, 9 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2385ecb2..846974f6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -106,11 +106,6 @@ Performance/CollectionLiteralInLoop: - 'lib/axlsx/package.rb' - 'lib/axlsx/workbook/worksheet/page_margins.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -Performance/Detect: - Exclude: - - 'lib/axlsx/workbook/workbook.rb' - # This cop supports safe autocorrection (--autocorrect). Performance/RedundantBlockCall: Exclude: @@ -121,7 +116,6 @@ Performance/RedundantMatch: Exclude: - 'lib/axlsx.rb' - 'lib/axlsx/stylesheet/color.rb' - - 'lib/axlsx/workbook/workbook.rb' # This cop supports safe autocorrection (--autocorrect). Performance/RedundantSplitRegexpArgument: @@ -132,7 +126,6 @@ Performance/RedundantSplitRegexpArgument: Performance/RegexpMatch: Exclude: - 'lib/axlsx/stylesheet/color.rb' - - 'lib/axlsx/workbook/workbook.rb' - 'lib/axlsx/workbook/worksheet/cell.rb' # This cop supports safe autocorrection (--autocorrect). 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(/.+!/, "")] |
