class Axlsx::DataTypeValidator
Validate that the class of the value provided is either an instance or the class of the allowed types and that any specified additional validation returns true.
Public Class Methods
validate(name, types, v, other=false)
click to toggle source
Perform validation @param [String] name The name of what is being validated. This is included in the error message @param [Array, Class] types A single class or array of classes that the value is validated against. @param [Block] other Any block that must evaluate to true for the value to be valid @raise [ArugumentError] Raised if the class of the value provided is not in the specified array of types or the block passed returns false @return [Boolean] true if validation succeeds. @see validate_boolean
# File lib/axlsx/util/validators.rb, line 54 def self.validate(name, types, v, other=false) if other.is_a?(Proc) raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v) 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]) end