Class: Schemacop::StringValidator

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

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, klass, option, #option, #option?, register, #resolve_type_klass, symbol, symbol_matches?, #type_filter_matches?, #type_label, type_matches?, #type_matches?

Constructor Details

#initialize(options = {}) ⇒ StringValidator

Returns a new instance of StringValidator



8
9
10
11
12
# File 'lib/schemacop/validator/string_validator.rb', line 8

def initialize(options = {})
  super(options)

  validate_options!
end

Instance Method Details

#validate(data, collector) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/schemacop/validator/string_validator.rb', line 14

def validate(data, collector)
  super

  if option?(:min) && data.size < option(:min)
    collector.error "String must be longer (>=) than #{option(:min)} characters."
  end
  if option?(:max) && data.size > option(:max)
    collector.error "String must be shorter (<=) than #{option(:max)} characters."
  end
end