summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/util/validators.rb
diff options
context:
space:
mode:
authorGeremia Taglialatela <[email protected]>2023-06-05 15:53:15 +0200
committerGeremia Taglialatela <[email protected]>2023-06-05 17:27:41 +0200
commit7fdbd745a2c914001a2174aeadae26b9c970ffaf (patch)
tree9b1a440ef0bee0ecaaeb7c991dcc9d8639cb7b6d /lib/axlsx/util/validators.rb
parenta2eeaeefca8deb3d26f3f8dc62976fe6bf1dafcf (diff)
downloadcaxlsx-7fdbd745a2c914001a2174aeadae26b9c970ffaf.tar.gz
caxlsx-7fdbd745a2c914001a2174aeadae26b9c970ffaf.zip
Fix Style/FormatString offenses
`Kernel#format` is faster and will avoid to allocate an array compared to `String#%`. ``` IPS: kernel_format: 3877614.2 i/s string_percent: 3531475.0 i/s - 1.10x (± 0.00) slower Memory: kernel_format: 160 allocated string_percent: 200 allocated - 1.25x more ```
Diffstat (limited to 'lib/axlsx/util/validators.rb')
-rw-r--r--lib/axlsx/util/validators.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index 48c12c13..1357f4f3 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -10,7 +10,7 @@ module Axlsx
# @raise [ArgumentError] Raised if the value provided is not in the list of choices.
# @return [Boolean] true if validation succeeds.
def self.validate(name, choices, v)
- raise ArgumentError, (ERR_RESTRICTION % [v.to_s, name, choices.inspect]) unless choices.include?(v)
+ raise ArgumentError, format(ERR_RESTRICTION, v.to_s, name, choices.inspect) unless choices.include?(v)
true
end
@@ -31,7 +31,7 @@ module Axlsx
else
min < value && value < max
end
- raise ArgumentError, (ERR_RANGE % [value.inspect, min.to_s, max.to_s, inclusive]) unless passes
+ raise ArgumentError, format(ERR_RANGE, value.inspect, min.to_s, max.to_s, inclusive) unless passes
end
end
@@ -41,7 +41,7 @@ module Axlsx
# @param [Regexp] regex The regular expression to evaluate
# @param [Any] v The value to validate.
def self.validate(name, regex, v)
- raise ArgumentError, (ERR_REGEX % [v.inspect, regex.to_s]) unless v.respond_to?(:to_s) && regex.match?(v.to_s)
+ raise ArgumentError, format(ERR_REGEX, v.inspect, regex.to_s) unless v.respond_to?(:to_s) && regex.match?(v.to_s)
end
end
@@ -56,14 +56,14 @@ module Axlsx
# @see validate_boolean
def self.validate(name, types, v, other = false)
if other.is_a?(Proc) && !other.call(v)
- raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
+ raise ArgumentError, format(ERR_TYPE, v.inspect, name, types.inspect)
end
v_class = v.is_a?(Class) ? v : v.class
Array(types).each do |t|
return if v_class <= t
end
- raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
+ raise ArgumentError, format(ERR_TYPE, v.inspect, name, types.inspect)
end
end