summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZsolt Kozaroczy <[email protected]>2023-05-25 10:49:42 +0200
committerGitHub <[email protected]>2023-05-25 10:49:42 +0200
commit4837fc882251188cbd028af8eb841503c8308c23 (patch)
tree9e559880610c735c5ec9f7206f70dc4a9f6863e9
parentf5c8c1384412ff1d235c2295a3b7449a21146ef5 (diff)
parent84a7132924b1c56f712a830b4e016a3c033923bf (diff)
downloadcaxlsx-4837fc882251188cbd028af8eb841503c8308c23.tar.gz
caxlsx-4837fc882251188cbd028af8eb841503c8308c23.zip
Merge pull request #234 from tagliala/chore/fix-collection-literal-in-loop
Do not use collection literal in loops
-rw-r--r--.rubocop_todo.yml6
-rw-r--r--lib/axlsx/package.rb6
-rw-r--r--lib/axlsx/util/constants.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/page_margins.rb9
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