Class: Lutaml::Xml::Type::ValueXmlMapping

Inherits:
Object
  • Object
show all
Includes:
SharedDsl
Defined in:
lib/lutaml/xml/type/value_xml_mapping.rb

Overview

XML mapping configuration for Type::Value classes

This class holds the XML configuration for value types, including namespace and XSD type information.

Examples:

Creating a custom XML mapping

mapping = ValueXmlMapping.new
mapping.namespace(MyNamespace)
mapping.xsd_type(:string)

Constant Summary

Constants included from SharedDsl

SharedDsl::VALID_XSD_TYPE_SYMBOLS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SharedDsl

#resolve_xsd_type, #resolve_xsd_type_from_class, #resolve_xsd_type_from_symbol, #validate_namespace_class!

Constructor Details

#initializeValueXmlMapping

Returns a new instance of ValueXmlMapping.



21
22
23
24
# File 'lib/lutaml/xml/type/value_xml_mapping.rb', line 21

def initialize
  @namespace_class = nil
  @xsd_type_name = nil
end

Instance Attribute Details

#namespace_classObject

Returns the value of attribute namespace_class.



19
20
21
# File 'lib/lutaml/xml/type/value_xml_mapping.rb', line 19

def namespace_class
  @namespace_class
end

#xsd_type_nameObject

Returns the value of attribute xsd_type_name.



19
20
21
# File 'lib/lutaml/xml/type/value_xml_mapping.rb', line 19

def xsd_type_name
  @xsd_type_name
end

Instance Method Details

#deep_dupValueXmlMapping

Create a deep duplicate of this mapping

Used for inheritance when a child type needs its own copy of the parent’s XML configuration.

Returns:



81
82
83
84
85
86
87
88
89
90
# File 'lib/lutaml/xml/type/value_xml_mapping.rb', line 81

def deep_dup
  self.class.new.tap do |dup|
    # namespace_class is a class reference, no need to deep copy
    dup.namespace_class = @namespace_class
    # xsd_type_name is a string, duplicate for safety
    if @xsd_type_name
      dup.xsd_type_name = @xsd_type_name.dup
    end
  end
end

#namespace(ns_class_or_symbol) ⇒ void

This method returns an undefined value.

Set the namespace for this Value type

Examples:

Setting namespace with XmlNamespace class

mapping.namespace(MyNamespace)

Setting blank namespace

mapping.namespace(:blank)

Inheriting parent namespace

mapping.namespace(:inherit)

Parameters:

  • ns_class_or_symbol (Class, Symbol)

    XmlNamespace class, :blank, or :inherit

Raises:



41
42
43
44
# File 'lib/lutaml/xml/type/value_xml_mapping.rb', line 41

def namespace(ns_class_or_symbol)
  validate_namespace_class!(ns_class_or_symbol)
  @namespace_class = ns_class_or_symbol
end

#namespace_prefixString?

Get the namespace prefix for this mapping

Returns:

  • (String, nil)

    the namespace prefix



56
57
58
# File 'lib/lutaml/xml/type/value_xml_mapping.rb', line 56

def namespace_prefix
  @namespace_class&.prefix_default
end

#namespace_uriString?

Get the namespace URI for this mapping

Returns:

  • (String, nil)

    the namespace URI



49
50
51
# File 'lib/lutaml/xml/type/value_xml_mapping.rb', line 49

def namespace_uri
  @namespace_class&.uri
end

#xsd_type(type) ⇒ void

This method returns an undefined value.

Set the XSD type name

Examples:

Setting XSD type with Symbol

mapping.xsd_type(:string)  # becomes 'xs:string'

Setting XSD type with Type class

mapping.xsd_type(Lutaml::Model::Type::String)

Parameters:

  • type (Symbol, Class)

    XSD type symbol or Type class



70
71
72
# File 'lib/lutaml/xml/type/value_xml_mapping.rb', line 70

def xsd_type(type)
  @xsd_type_name = resolve_xsd_type(type)
end