Class: Lutaml::Model::NamespaceBinding

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/register/namespace_binding.rb

Overview

Represents a binding between a register and a namespace.

This enables version-aware type resolution where different namespaces can map to different type implementations.

Examples:

binding = NamespaceBinding.new(
  register_id: :xmi_20131001,
  namespace_class: Xmi::Namespace::Omg::Xmi20131001
)

binding.register_id   # => :xmi_20131001
binding.namespace_uri # => "http://www.omg.org/spec/XMI/20131001"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(register_id:, namespace_class:) ⇒ NamespaceBinding

Create a new namespace binding.

Parameters:

  • register_id (Symbol)

    The register ID

  • namespace_class (Class)

    A Lutaml::Xml::Namespace subclass

Raises:

  • (ArgumentError)

    If namespace_class is not a Lutaml::Xml::Namespace



38
39
40
41
42
43
44
45
# File 'lib/lutaml/model/register/namespace_binding.rb', line 38

def initialize(register_id:, namespace_class:)
  validate_namespace_class!(namespace_class)

  @register_id = register_id.to_sym
  @namespace_class = namespace_class
  @namespace_uri = namespace_class.uri
  freeze
end

Instance Attribute Details

#namespace_classClass (readonly)

Returns The namespace class.

Returns:

  • (Class)

    The namespace class



26
27
28
# File 'lib/lutaml/model/register/namespace_binding.rb', line 26

def namespace_class
  @namespace_class
end

#namespace_uriString (readonly)

Returns The namespace URI.

Returns:

  • (String)

    The namespace URI



30
31
32
# File 'lib/lutaml/model/register/namespace_binding.rb', line 30

def namespace_uri
  @namespace_uri
end

#register_idSymbol (readonly)

Returns The register ID.

Returns:

  • (Symbol)

    The register ID



22
23
24
# File 'lib/lutaml/model/register/namespace_binding.rb', line 22

def register_id
  @register_id
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Check equality with another NamespaceBinding.

Parameters:

  • other (Object)

    Object to compare

Returns:

  • (Boolean)

    true if equal



52
53
54
55
56
# File 'lib/lutaml/model/register/namespace_binding.rb', line 52

def ==(other)
  return false unless other.is_a?(NamespaceBinding)

  register_id == other.register_id && namespace_uri == other.namespace_uri
end

#hashInteger

Hash code for use as hash key.

Returns:

  • (Integer)

    Hash code



64
65
66
# File 'lib/lutaml/model/register/namespace_binding.rb', line 64

def hash
  [register_id, namespace_uri].hash
end

#to_sString Also known as: inspect

Human-readable representation.

Returns:

  • (String)

    String representation



72
73
74
# File 'lib/lutaml/model/register/namespace_binding.rb', line 72

def to_s
  "#<#{self.class.name} register=#{register_id} namespace=#{namespace_uri}>"
end