Class: SchematronFile

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
DigestedFile::ClassMethods
Includes:
DigestedFile
Defined in:
app/models/schematron_file.rb

Overview

Class representing the file containing schematron

Should be considered immutable in principle after creation - in practice, there's not a simple way to render a File object immutable.

Delegates most operations to File object.

Constant Summary

FILE_DIR =

Directory that processed schematron files are stored in

File.join(Rails.root, 'public', 'schematrons')
INSPECT_SLUG =

Slug to prepend to File in console description of object

'Schematron'

Instance Attribute Summary

Attributes included from DigestedFile

#digest

Instance Method Summary (collapse)

Methods included from DigestedFile::ClassMethods

[], digests, filenames

Methods included from DigestedFile

#initialize

Instance Method Details

- (Array<Hash>) issue_attrs

Return an array of hashes of issue attribute values suitable

for passing in as nested attributes to Schematron constructor

Returns:

  • (Array<Hash>)

    A representation of the XML content for use in constructing DB representations of individual issues



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/schematron_file.rb', line 23

def issue_attrs
  rep = {}
  xml = Nokogiri::XML(self, nil, 'UTF-8') {|config| config.nonet}
  xml.remove_namespaces!
  diags = xml.xpath('//diagnostic')
  xml.xpath('//rule').map do |rule|
    label = rule.xpath('./comment()').text.strip
    context = rule['context']
    manual = rule.ancestors('pattern').first['id'].match(/-manual\Z/) ? true : false
    issues = rule.xpath('./assert').map do |assert|
      {
        rule_label: label,
        rule_context: context,
        manual: manual, #rule stuff
        identifier: assert['diagnostics'],
        test: assert['test'],
        message: assert.content.strip,
        alternate_issue_id: diags.filter("[@id='#{assert['diagnostics']}']")
          .first
          .content
          .match(/(?<=Ref-number: ).*$/)[0]
      }
    end
  end.flatten
end