Class: Lutaml::Xsd::SchemaLocationMapping

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

Overview

Represents a schema location mapping for resolving import/include paths

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = nil, from: nil, to: nil, pattern: nil) ⇒ SchemaLocationMapping

Override initialize to auto-detect Regexp patterns Supports both hash argument (for Lutaml::Model) and keyword arguments

Parameters:

  • attributes (Hash) (defaults to: nil)

    Attributes hash (for deserialization)

  • from (String, Regexp) (defaults to: nil)

    The source pattern

  • to (String) (defaults to: nil)

    The target path

  • pattern (Boolean, nil) (defaults to: nil)

    Explicit pattern flag (optional)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lutaml/xsd/schema_location_mapping.rb', line 28

def initialize(attributes = nil, from: nil, to: nil, pattern: nil,
**)
  # Handle hash argument from Lutaml::Model deserialization
  if attributes.is_a?(Hash)
    from = attributes[:from] || attributes["from"]
    to = attributes[:to] || attributes["to"]
    pattern = attributes[:pattern] || attributes["pattern"]
  end

  # Auto-detect if from is a Regexp
  detected_pattern = from.is_a?(Regexp)

  # Convert Regexp to source string for storage
  from_str = detected_pattern ? from.source : from

  # Use explicit pattern flag if provided, otherwise use detected value
  final_pattern = pattern.nil? ? detected_pattern : pattern

  super(from: from_str, to: to, pattern: final_pattern, **)
end

Class Method Details

.from_hash(mapping) ⇒ SchemaLocationMapping

Convert hash-based mapping to SchemaLocationMapping instance

Parameters:

  • mapping (Hash)

    Hash with :from/:to or “from”/“to” keys

Returns:



52
53
54
55
56
57
58
# File 'lib/lutaml/xsd/schema_location_mapping.rb', line 52

def self.from_hash(mapping)
  from = mapping[:from] || mapping["from"]
  to = mapping[:to] || mapping["to"]
  pattern = mapping[:pattern] || mapping["pattern"]

  new(from: from, to: to, pattern: pattern)
end

Instance Method Details

#to_glob_formatHash

Convert to hash format compatible with Glob.schema_mappings

Returns:

  • (Hash)


62
63
64
65
66
67
# File 'lib/lutaml/xsd/schema_location_mapping.rb', line 62

def to_glob_format
  {
    from: pattern ? Regexp.new(from) : from,
    to: to,
  }
end