lib/schematron_validator.rb in cqm-validators-0.1.1 vs lib/schematron_validator.rb in cqm-validators-1.0.1.0

- old
+ new

@@ -1,38 +1,37 @@ +# frozen_string_literal: true + module CqmValidators - module Schematron - NAMESPACE = {"svrl" => "http://purl.oclc.org/dsdl/svrl"} - DIR = File.expand_path("../../", __FILE__) - ISO_SCHEMATRON = File.join(DIR, 'lib/schematron/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl') + module Schematron + NAMESPACE = { 'svrl' => 'http://purl.oclc.org/dsdl/svrl' }.freeze + DIR = File.expand_path('..', __dir__) + ISO_SCHEMATRON = File.join(DIR, 'lib/schematron/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl') - class Validator - include BaseValidator + class Validator + include BaseValidator - if RUBY_PLATFORM != "java" - require_relative "schematron/c_processor" - include Schematron::CProcessor - else - require_relative 'schematron/java_processor' - include Schematron::JavaProcessor - end + if RUBY_PLATFORM != 'java' + require_relative 'schematron/c_processor' + include Schematron::CProcessor + else + require_relative 'schematron/java_processor' + include Schematron::JavaProcessor + end - def initialize(name,schematron_file) - @name = name - @schematron_file = schematron_file - end + def initialize(name, schematron_file) + @name = name + @schematron_file = schematron_file + end - def validate(document,data = {}) - file_errors = document.errors.select { |e| e.fatal? || e.error? } - if file_errors - file_errors.each do |error| - build_error(error, '/', data[:file_name]) - end - end - errors = get_errors(document).root.xpath("//svrl:failed-assert",NAMESPACE).map do |el| - build_error(el.xpath('svrl:text',NAMESPACE).text, el['location'], data[:file_name]) - end - errors.uniq{|e| "#{e.location}#{e.message}"} - end - - end - end + def validate(document, data = {}) + file_errors = get_document(document).errors.select { |e| e.fatal? || e.error? } + file_errors&.each do |error| + build_error(error, '/', data[:file_name]) + end + errors = get_errors(document).root.xpath('//svrl:failed-assert', NAMESPACE).map do |el| + build_error(el.xpath('svrl:text', NAMESPACE).text, el['location'], data[:file_name]) + end + errors.uniq { |e| "#{e.location}#{e.message}" } + end + end + end end