Class: Lutaml::Xml::Schema::Xsd::FileValidationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/schema/xsd/file_validation_result.rb

Overview

Value object representing the validation result for a single file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, valid:, error: nil, detected_version: nil) ⇒ FileValidationResult

Returns a new instance of FileValidationResult.

Parameters:

  • file (String)

    Path to the validated file

  • valid (Boolean)

    Whether the file is valid

  • error (String, nil) (defaults to: nil)

    Error message if validation failed

  • detected_version (String, nil) (defaults to: nil)

    Detected XSD version (1.0 or 1.1)



15
16
17
18
19
20
# File 'lib/lutaml/xml/schema/xsd/file_validation_result.rb', line 15

def initialize(file:, valid:, error: nil, detected_version: nil)
  @file = file
  @valid = valid
  @error = error
  @detected_version = detected_version
end

Instance Attribute Details

#detected_versionObject (readonly)

Returns the value of attribute detected_version.



9
10
11
# File 'lib/lutaml/xml/schema/xsd/file_validation_result.rb', line 9

def detected_version
  @detected_version
end

#errorObject (readonly)

Returns the value of attribute error.



9
10
11
# File 'lib/lutaml/xml/schema/xsd/file_validation_result.rb', line 9

def error
  @error
end

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/lutaml/xml/schema/xsd/file_validation_result.rb', line 9

def file
  @file
end

Instance Method Details

#failure?Boolean

Returns true if the file failed validation.

Returns:

  • (Boolean)

    true if the file failed validation



28
29
30
# File 'lib/lutaml/xml/schema/xsd/file_validation_result.rb', line 28

def failure?
  !success?
end

#success?Boolean

Returns true if the file passed validation.

Returns:

  • (Boolean)

    true if the file passed validation



23
24
25
# File 'lib/lutaml/xml/schema/xsd/file_validation_result.rb', line 23

def success?
  @valid
end

#to_hHash

Convert to hash for backward compatibility

Returns:

  • (Hash)

    Hash representation of the result



34
35
36
37
38
39
40
41
# File 'lib/lutaml/xml/schema/xsd/file_validation_result.rb', line 34

def to_h
  {
    file: file,
    valid: success?,
    error: error,
    detected_version: detected_version,
  }.compact
end

#to_sString

Returns Human-readable string representation.

Returns:

  • (String)

    Human-readable string representation



44
45
46
47
48
49
50
# File 'lib/lutaml/xml/schema/xsd/file_validation_result.rb', line 44

def to_s
  if success?
    "#{file}: VALID"
  else
    "#{file}: INVALID - #{error}"
  end
end