Class: Lutaml::Xsd::FileValidationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/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)



13
14
15
16
17
18
# File 'lib/lutaml/xsd/file_validation_result.rb', line 13

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.



7
8
9
# File 'lib/lutaml/xsd/file_validation_result.rb', line 7

def detected_version
  @detected_version
end

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/lutaml/xsd/file_validation_result.rb', line 7

def error
  @error
end

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/lutaml/xsd/file_validation_result.rb', line 7

def file
  @file
end

Instance Method Details

#failure?Boolean

Returns true if the file failed validation.

Returns:

  • (Boolean)

    true if the file failed validation



26
27
28
# File 'lib/lutaml/xsd/file_validation_result.rb', line 26

def failure?
  !success?
end

#success?Boolean

Returns true if the file passed validation.

Returns:

  • (Boolean)

    true if the file passed validation



21
22
23
# File 'lib/lutaml/xsd/file_validation_result.rb', line 21

def success?
  @valid
end

#to_hHash

Convert to hash for backward compatibility

Returns:

  • (Hash)

    Hash representation of the result



32
33
34
35
36
37
38
39
# File 'lib/lutaml/xsd/file_validation_result.rb', line 32

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



42
43
44
45
46
47
48
# File 'lib/lutaml/xsd/file_validation_result.rb', line 42

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