Class: CqmValidators::Schema::Validator
- Inherits:
-
Object
- Object
- CqmValidators::Schema::Validator
- Includes:
- BaseValidator
- Defined in:
- lib/schema_validator.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(name, schema_file) ⇒ Validator
constructor
A new instance of Validator.
-
#validate(document, data = {}) ⇒ Object
Validate the document against the configured schema.
Methods included from BaseValidator
Constructor Details
#initialize(name, schema_file) ⇒ Validator
Returns a new instance of Validator.
8 9 10 11 12 |
# File 'lib/schema_validator.rb', line 8 def initialize(name, schema_file) @name = name @schema_file = schema_file @xsd = Nokogiri::XML::Schema(File.new(@schema_file)) end |
Instance Method Details
#validate(document, data = {}) ⇒ Object
Validate the document against the configured schema
15 16 17 18 19 20 21 |
# File 'lib/schema_validator.rb', line 15 def validate(document, data = {}) @xsd.errors.clear doc = get_document(document) @xsd.validate(doc).map do |error| build_error(error., '/', data[:file_name]) end end |