diff options
| author | Geremia Taglialatela <[email protected]> | 2023-05-17 11:17:45 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-05-24 10:03:50 +0200 |
| commit | 84a7132924b1c56f712a830b4e016a3c033923bf (patch) | |
| tree | 1bccc27e18be9287d568cd4c6313dbe33495acad | |
| parent | 14b7da239879d5299775c48666b43f3016add8ec (diff) | |
| download | caxlsx-84a7132924b1c56f712a830b4e016a3c033923bf.tar.gz caxlsx-84a7132924b1c56f712a830b4e016a3c033923bf.zip | |
Do not use collection literal in loops
Also refactors Page margins to avoid code duplication
| -rw-r--r-- | .rubocop_todo.yml | 6 | ||||
| -rw-r--r-- | lib/axlsx/package.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/util/constants.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/page_margins.rb | 9 |
4 files changed, 11 insertions, 14 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a0260f2e..dab9ffb2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -77,12 +77,6 @@ Lint/UnusedMethodArgument: - 'lib/axlsx/package.rb' - 'lib/axlsx/util/validators.rb' -# Configuration parameters: MinSize. -Performance/CollectionLiteralInLoop: - Exclude: - - 'lib/axlsx/package.rb' - - 'lib/axlsx/workbook/worksheet/page_margins.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: separated, grouped diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 2983ed72..20195ddc 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -330,11 +330,11 @@ module Axlsx end exts = workbook.images.map { |image| image.extname.downcase } exts.uniq.each do |ext| - ct = if ['jpeg', 'jpg'].include?(ext) + ct = if JPEG_EXS.include?(ext) JPEG_CT - elsif ext == 'gif' + elsif ext == GIF_EX GIF_CT - elsif ext == 'png' + elsif ext == PNG_EX PNG_CT end c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext) diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb index 138c8bf0..459e0099 100644 --- a/lib/axlsx/util/constants.rb +++ b/lib/axlsx/util/constants.rb @@ -166,8 +166,8 @@ module Axlsx # xml content type extensions XML_EX = "xml" - # jpeg extension - JPEG_EX = "jpeg" + # jpeg extensions + JPEG_EXS = ["jpeg", "jpg"].freeze # gif extension GIF_EX = "gif" diff --git a/lib/axlsx/workbook/worksheet/page_margins.rb b/lib/axlsx/workbook/worksheet/page_margins.rb index 4d133c5a..9c2ddd8e 100644 --- a/lib/axlsx/workbook/worksheet/page_margins.rb +++ b/lib/axlsx/workbook/worksheet/page_margins.rb @@ -29,7 +29,10 @@ module Axlsx parse_options options end - serializable_attributes :left, :right, :bottom, :top, :header, :footer + # Possible margins to set + MARGIN_KEYS = [:left, :right, :top, :bottom, :header, :footer].freeze + + serializable_attributes(*MARGIN_KEYS) # Default left and right margin (in inches) DEFAULT_LEFT_RIGHT = 0.75 @@ -65,10 +68,10 @@ module Axlsx attr_reader :footer # Set some or all margins at once. - # @param [Hash] margins the margins to set (possible keys are :left, :right, :top, :bottom, :header and :footer). + # @param [Hash] margins the margins to set. See {MARGIN_KEYS} for a list of possible keys. def set(margins) margins.select do |k, v| - next unless [:left, :right, :top, :bottom, :header, :footer].include? k + next unless MARGIN_KEYS.include? k send("#{k}=", v) end |
