Class: HealthDataStandards::Validate::Schema::Validator

Inherits:
Object
  • Object
show all
Includes:
BaseValidator
Defined in:
lib/health-data-standards/validate/schema_validator.rb

Direct Known Subclasses

CDA

Instance Method Summary collapse

Methods included from BaseValidator

#build_error, #get_document

Constructor Details

#initialize(name, schema_file) ⇒ Validator

Returns a new instance of Validator.



7
8
9
10
11
# File 'lib/health-data-standards/validate/schema_validator.rb', line 7

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



14
15
16
17
18
19
20
# File 'lib/health-data-standards/validate/schema_validator.rb', line 14

def validate(document,data={})
  @xsd.errors.clear
  doc = get_document(document)
  @xsd.validate(doc).map do |error|
    build_error(error.message, "/", data[:file_name])
  end
end