Class: Schemacop::V2::NumberValidator

Inherits:
Node
  • Object
show all
Defined in:
lib/schemacop/v2/validator/number_validator.rb

Direct Known Subclasses

FloatValidator, IntegerValidator

Instance Attribute Summary

Attributes inherited from Node

#options

Instance Method Summary collapse

Methods inherited from Node

build, class_matches?, clear_klasses, clear_symbols, #exec_block, #initialize, klass, #option, option, #option?, register, #resolve_type_klass, symbol, symbol_matches?, #type_filter_matches?, #type_label, type_matches?, #type_matches?

Constructor Details

This class inherits a constructor from Schemacop::V2::Node

Instance Method Details

#validate(data, collector) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/schemacop/v2/validator/number_validator.rb', line 9

def validate(data, collector)
  super

  if option?(:min) && data < option(:min)
    collector.error "Value must be >= #{option(:min)}."
  end
  if option?(:max) && data > option(:max)
    collector.error "Value must be <= #{option(:max)}."
  end
end