Class: SHACL::ValidationReport

Inherits:
Object
  • Object
show all
Includes:
RDF::Enumerable
Defined in:
lib/shacl/validation_report.rb

Overview

A SHACL Validateion Report.

Collects the individual ValidationResult instances and provides a conforms boolean accessor.

Allows the report to be serialized as a set of RDF Statements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ ValidationReport

Creates a report from the set of results

Parameters:



27
28
29
# File 'lib/shacl/validation_report.rb', line 27

def initialize(results)
  @all_results = Array(results)
end

Instance Attribute Details

#all_resultsObject (readonly)

All results, both conforming and non-conforming



20
21
22
# File 'lib/shacl/validation_report.rb', line 20

def all_results
  @all_results
end

Instance Method Details

#==(other) ⇒ Boolean

Two reports are eq if they have the same number of results and each result equals a result in the other report.

Parameters:

Returns:

  • (Boolean)


78
79
80
81
# File 'lib/shacl/validation_report.rb', line 78

def ==(other)
  return false unless other.is_a?(ValidationReport)
  count == other.count && other.results.all? {|r| results.include?(r)}
end

#conform?Boolean

Do the individual results indicate conformance?

Returns:

  • (Boolean)


51
52
53
# File 'lib/shacl/validation_report.rb', line 51

def conform?
  results.empty?
end

#countInteger

The number of non-conforming results

Returns:

  • (Integer)


43
44
45
# File 'lib/shacl/validation_report.rb', line 43

def count
  results.length
end

#each {|statement| ... }

This method returns an undefined value.

Yields statements for this report

Yields:

  • (statement)

    each statement

Yield Parameters:

  • statement (RDF::Statement)

Yield Returns:

  • (void)

    ignored



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/shacl/validation_report.rb', line 99

def each(&block)
  subject = RDF::Node.new
  block.call(RDF::Statement(subject, RDF.type, RDF::Vocab::SHACL.ValidationReport))
  block.call(RDF::Statement(subject, RDF::Vocab::SHACL.conforms, RDF::Literal(conform?)))
  results.each do |result|
    result_subject = nil
    result.each do |statement|
      result_subject ||= statement.subject
      yield(statement)
    end
    yield(RDF::Statement(subject, RDF::Vocab::SHACL.result, result_subject))
  end
end

#linter_messagesHash{Symbol => Hash{Symbol => Array<String>}}

Create a hash of messages appropriate for linter-like output.

Returns:

  • (Hash{Symbol => Hash{Symbol => Array<String>}})


87
88
89
# File 'lib/shacl/validation_report.rb', line 87

def linter_messages
  results.inject({}) {|memo, result| memo.deep_merge(result.linter_message)}
end

#resultsArray<ValidationResult>

The non-conforming results

Returns:



35
36
37
# File 'lib/shacl/validation_report.rb', line 35

def results
  @all_results.reject(&:conform?)
end

#to_sObject



70
71
72
# File 'lib/shacl/validation_report.rb', line 70

def to_s
  results.map(&:to_s).join("\n")
end

#to_sxp(**options) ⇒ String

Transform Report to SXP

Returns:

  • (String)


66
67
68
# File 'lib/shacl/validation_report.rb', line 66

def to_sxp(**options)
  self.to_sxp_bin.to_sxp(**options)
end

#to_sxp_binObject

The number of results



58
59
60
# File 'lib/shacl/validation_report.rb', line 58

def to_sxp_bin
  [:ValidationReport, conform?, results].to_sxp_bin
end