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.0.0.7/Factur-X_1.0.07_EN16931.sch' ]
- SCHEMA =
[ '../../schemas/zugferd_1/ZUGFeRD1p0.xsd', '../../schemas/factur-x_1.0.0.7/Factur-X_1.0.07_EN16931.xsd' ]
- SCHEMA_DIR =
[ '../../schemas/zugferd_1', '../../schemas/factur-x_1.0.0.7/' ]
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.
38 39 40 41 |
# File 'lib/secretariat/validator.rb', line 38 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.
37 38 39 |
# File 'lib/secretariat/validator.rb', line 37 def doc @doc end |
#version ⇒ Object
Returns the value of attribute version.
37 38 39 |
# File 'lib/secretariat/validator.rb', line 37 def version @version end |
Instance Method Details
#schema ⇒ Object
43 44 45 |
# File 'lib/secretariat/validator.rb', line 43 def schema Nokogiri::XML.Schema open(File.join(__dir__, SCHEMA[version - 1])) end |
#schematron_path ⇒ Object
47 48 49 |
# File 'lib/secretariat/validator.rb', line 47 def schematron_path File.join(__dir__, SCHEMATRON[version - 1]) end |
#validate_against_schema ⇒ Object
51 52 53 |
# File 'lib/secretariat/validator.rb', line 51 def validate_against_schema schema.validate(doc) end |
#validate_against_schematron ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/secretariat/validator.rb', line 55 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.match("[valid]") out.lines end end |