summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/util/validators.rb
diff options
context:
space:
mode:
authorPaul Kmiec <[email protected]>2023-05-13 10:18:50 -0700
committerPaul Kmiec <[email protected]>2023-05-15 16:58:24 -0700
commitaf8360755fe21f4e9d30e943ba0b2be3c0128d28 (patch)
treece7ea39f84aea2a988594eab9e2bb9a667713be8 /lib/axlsx/util/validators.rb
parente57d67b31d0edbdf3ffe1f2e16f1c262e1b48c4b (diff)
downloadcaxlsx-af8360755fe21f4e9d30e943ba0b2be3c0128d28.tar.gz
caxlsx-af8360755fe21f4e9d30e943ba0b2be3c0128d28.zip
Improve boolean validation constants (i.e. Axlsx::VALID_BOOLEAN_VALUES)
Added VALID_BOOLEAN_TRUE_VALUES and VALID_BOOLEAN_FALSE_VALUES so that those can be re-used in other placed and have the same notion of what a valid boolean value is. For example, we can use the true values in `Cell#u=`. Additionally, since validate_boolean / BOOLEAN_VALIDATOR are invoked so frequently, putting the likely values at the front can actually make a non-trivial difference. Since VALID_BOOLEAN_VALUES is derived from VALID_BOOLEAN_TRUE_VALUES and VALID_BOOLEAN_FALSE_VALUES, we use `Array#zip` to still end up with good order.
Diffstat (limited to 'lib/axlsx/util/validators.rb')
-rw-r--r--lib/axlsx/util/validators.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index 0004f51a..752ffc76 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -106,8 +106,10 @@ module Axlsx
DataTypeValidator.validate :signed_int, Integer, v
end
- VALID_BOOLEAN_CLASSES = [String, Integer, Symbol, TrueClass, FalseClass].freeze
- VALID_BOOLEAN_VALUES = [0, 1, 'true', 'false', :true, :false, true, false, '0', '1'].freeze
+ VALID_BOOLEAN_CLASSES = [TrueClass, FalseClass, Integer, String, Symbol].freeze
+ VALID_BOOLEAN_TRUE_VALUES = [true, 1, '1', 'true', :true].freeze
+ VALID_BOOLEAN_FALSE_VALUES = [false, 0, '0', 'false', :false].freeze
+ VALID_BOOLEAN_VALUES = VALID_BOOLEAN_TRUE_VALUES.zip(VALID_BOOLEAN_FALSE_VALUES).flatten.freeze
BOOLEAN_VALIDATOR = lambda { |arg| VALID_BOOLEAN_VALUES.include?(arg) }
# Requires that the value is a form that can be evaluated as a boolean in an xml document.