Class: Lutaml::Xsd::NamespaceUriRemapping

Inherits:
Model::Serializable
  • Object
show all
Defined in:
lib/lutaml/xsd/namespace_uri_remapping.rb

Overview

Namespace URI remapping rule (URI → URI transformation)

Instance Method Summary collapse

Instance Method Details

#apply(uri) ⇒ String

Apply remapping to a URI

Parameters:

  • uri (String)

    Namespace URI

Returns:

  • (String)

    Remapped URI or original



70
71
72
# File 'lib/lutaml/xsd/namespace_uri_remapping.rb', line 70

def apply(uri)
  uri == from_uri ? to_uri : uri
end

#valid?Boolean

Check if remapping is valid

Returns:

  • (Boolean)


57
58
59
# File 'lib/lutaml/xsd/namespace_uri_remapping.rb', line 57

def valid?
  validate.valid?
end

#validateValidationResult

Validate remapping

Returns:



20
21
22
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
48
49
50
51
52
53
# File 'lib/lutaml/xsd/namespace_uri_remapping.rb', line 20

def validate
  errors = []

  from_missing = from_uri.nil? || from_uri.empty?
  to_missing = to_uri.nil? || to_uri.empty?

  if from_missing
    errors << ValidationError.create(
      field: :from_uri,
      message: "Source URI is required",
      constraint: "presence",
    )
  end

  if to_missing
    errors << ValidationError.create(
      field: :to_uri,
      message: "Target URI is required",
      constraint: "presence",
    )
  end

  # Only check equality if both URIs are present
  if !from_missing && !to_missing && from_uri == to_uri
    errors << ValidationError.create(
      field: :to_uri,
      message: "Target URI must be different from source URI",
      value: to_uri,
      constraint: "!= from_uri",
    )
  end

  errors.empty? ? ValidationResult.success : ValidationResult.failure(errors)
end

#validate!Object

Raise error if invalid



63
64
65
# File 'lib/lutaml/xsd/namespace_uri_remapping.rb', line 63

def validate!
  validate.validate!
end