Module: Mathematical::Validator
- Included in:
- Mathematical
- Defined in:
- lib/mathematical/validator.rb
Constant Summary collapse
- FORMAT_TYPES =
[:svg, :png, :mathml].freeze
- RENDER_TYPES =
[:parse, :filter, :text_filter, :strict_filter].freeze
Instance Method Summary collapse
- #validate_config(config) ⇒ Object
- #validate_content(maths) ⇒ Object
- #validate_string(maths) ⇒ Object
Instance Method Details
#validate_config(config) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mathematical/validator.rb', line 7 def validate_config(config) fail(TypeError, 'maxsize must be an integer!') unless config[:maxsize].is_a? Fixnum fail(TypeError, 'maxsize cannot be less than 0!') if config[:maxsize] < 0 fail(TypeError, 'format must be a symbol!') unless config[:format].is_a? Symbol fail(TypeError, "format type must be one of the following formats: #{FORMAT_TYPES.join(', ')}") unless FORMAT_TYPES.include?(config[:format]) if config[:delimiter].is_a?(Symbol) Configuration::Delimiters.option_exists?(config[:delimiter]) elsif config[:delimiter].is_a?(Array) config[:delimiter] = [nil] if config[:delimiter].empty? config[:delimiter].each do |delim| Configuration::Delimiters.option_exists?(delim) end else fail(TypeError, 'delimiter type must be a valid symbol or array of symbols') end end |
#validate_content(maths) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/mathematical/validator.rb', line 25 def validate_content(maths) if maths.is_a? Array maths.map { |m| validate_string(m) } else validate_string(maths) end end |
#validate_string(maths) ⇒ Object
33 34 35 36 |
# File 'lib/mathematical/validator.rb', line 33 def validate_string(maths) fail(ArgumentError, 'input must be string!') unless maths.is_a?(String) maths.strip end |