diff options
| author | Zsolt Kozaroczy <[email protected]> | 2023-05-17 09:50:16 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-17 09:50:16 +0200 |
| commit | 72d6411b9365df0bccbe1ac43f793fc7d7ab369f (patch) | |
| tree | 8e172b42e8ee104a0b2dca2283b2d8ac0076e846 | |
| parent | b099c0195f19458c1484f389955a2a0cf085a7ca (diff) | |
| parent | 5cda9e7f226a6d0f9ca38ba501c024f3bb564244 (diff) | |
| download | caxlsx-72d6411b9365df0bccbe1ac43f793fc7d7ab369f.tar.gz caxlsx-72d6411b9365df0bccbe1ac43f793fc7d7ab369f.zip | |
Merge pull request #229 from tagliala/chore/use-detect-and-include
Use `include?` and `find` for performance
| -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 713bc2b6..ed0c7d35 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -103,11 +103,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: @@ -117,7 +112,6 @@ Performance/RedundantBlockCall: Performance/RedundantMatch: Exclude: - 'lib/axlsx/stylesheet/color.rb' - - 'lib/axlsx/workbook/workbook.rb' # This cop supports safe autocorrection (--autocorrect). Performance/RedundantSplitRegexpArgument: @@ -128,7 +122,6 @@ Performance/RedundantSplitRegexpArgument: Performance/RegexpMatch: Exclude: - 'lib/axlsx/stylesheet/color.rb' - - 'lib/axlsx/workbook/workbook.rb' # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. 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(/.+!/, "")] |
