Class: Secretariat::Validator
- Inherits:
-
Object
- Object
- Secretariat::Validator
- Defined in:
- lib/secretariat/validator.rb
Constant Summary collapse
- SCHEMATRON =
[ '../../schemas/zugferd_1/ZUGFeRD1p0.sch', '../../schemas/factur-x_1/Factur-X_1.07.2_EN16931.sch' ]
- SCHEMA =
[ '../../schemas/zugferd_1/ZUGFeRD1p0.xsd', '../../schemas/factur-x_1/Factur-X_1.07.2_EN16931.xsd' ]
- SCHEMA_DIR =
[ '../../schemas/zugferd_1', '../../schemas/factur-x_1/' ]
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(io_or_str, version: 1) ⇒ Validator
constructor
A new instance of Validator.
- #schema ⇒ Object
- #schematron_path ⇒ Object
- #validate_against_schema ⇒ Object
- #validate_against_schematron ⇒ Object
Constructor Details
#initialize(io_or_str, version: 1) ⇒ Validator
Returns a new instance of Validator.
42 43 44 45 |
# File 'lib/secretariat/validator.rb', line 42 def initialize(io_or_str, version: 1) @doc = Nokogiri.XML(io_or_str) @version = version end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
41 42 43 |
# File 'lib/secretariat/validator.rb', line 41 def doc @doc end |
#version ⇒ Object
Returns the value of attribute version.
41 42 43 |
# File 'lib/secretariat/validator.rb', line 41 def version @version end |
Instance Method Details
#schema ⇒ Object
47 48 49 |
# File 'lib/secretariat/validator.rb', line 47 def schema Nokogiri::XML.Schema open(File.join(__dir__, SCHEMA[version - 1])) end |
#schematron_path ⇒ Object
51 52 53 |
# File 'lib/secretariat/validator.rb', line 51 def schematron_path File.join(__dir__, SCHEMATRON[version - 1]) end |
#validate_against_schema ⇒ Object
55 56 57 |
# File 'lib/secretariat/validator.rb', line 55 def validate_against_schema schema.validate(doc) end |
#validate_against_schematron ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/secretariat/validator.rb', line 59 def validate_against_schematron Dir.mktmpdir do |dir| docpath = File.join(dir, 'doc.xml') File.write(docpath, doc, mode: 'wb') jarpath = File.join(__dir__, '../..', 'bin', 'schxslt-cli.jar') out = `java -jar #{jarpath} -v -d #{docpath} -s #{schematron_path}` return [] if out.start_with?("[valid]") return process_schematron_errors(out) end end |