Class: Lutaml::Xsd::SchemaLocationMapping
- Inherits:
-
Model::Serializable
- Object
- Model::Serializable
- Lutaml::Xsd::SchemaLocationMapping
- Defined in:
- lib/lutaml/xsd/schema_location_mapping.rb
Overview
Represents a schema location mapping for resolving import/include paths
Class Method Summary collapse
-
.from_hash(mapping) ⇒ SchemaLocationMapping
Convert hash-based mapping to SchemaLocationMapping instance.
Instance Method Summary collapse
-
#initialize(attributes = nil, from: nil, to: nil, pattern: nil) ⇒ SchemaLocationMapping
constructor
Override initialize to auto-detect Regexp patterns Supports both hash argument (for Lutaml::Model) and keyword arguments.
-
#to_glob_format ⇒ Hash
Convert to hash format compatible with Glob.schema_mappings.
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
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
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_format ⇒ Hash
Convert to hash format compatible with Glob.schema_mappings
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 |