Module: Xmi::Parsing

Defined in:
lib/xmi/parsing.rb

Overview

Unified API for XMI parsing with version support

This module provides a consistent interface for parsing XMI documents with automatic version detection or explicit version specification.

Examples:

# Auto-detect version from XML
doc = Xmi::Parsing.parse(xml_content)
# Force specific version
doc = Xmi::Parsing.parse(xml_content, version: "20131001")

Class Method Summary collapse

Class Method Details

.detect_version(xml) ⇒ Hash

Detect XMI version without full parsing

Parameters:

  • xml (String)

    XML content

Returns:

  • (Hash)

    Version information with :versions and :uris keys



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/xmi/parsing.rb', line 60

def detect_version(xml)
  versions = NamespaceDetector.detect_versions(xml)
  uris = NamespaceDetector.detect_namespace_uris(xml)

  {
    versions: versions,
    uris: uris,
    xmi_version: versions[:xmi],
    uml_version: versions[:uml],
  }
end

.parse(xml, options = {}) ⇒ Root, Object

Parse XMI with automatic version detection

Parameters:

  • xml (String, IO)

    XML content or stream

  • options (Hash) (defaults to: {})

    Parsing options

Options Hash (options):

  • :version (String)

    Force specific version

  • :register (Lutaml::Model::Register)

    Use specific register

  • :model_class (Class)

    Model class to parse into

  • :strict (Boolean)

    Raise on unknown elements

Returns:

  • (Root, Object)

    Parsed XMI document



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/xmi/parsing.rb', line 29

def parse(xml, options = {})
  xml_content = xml.respond_to?(:read) ? xml.read : xml.to_s

  Xmi.init_versioning! unless Xmi.versioning_initialized?

  register = determine_register(xml_content, options)
  model_class = options[:model_class] || Root

  if register
    model_class.from_xml(xml_content, register: register)
  else
    # Fallback to default parsing (existing behavior)
    model_class.from_xml(xml_content)
  end
end

.parse_file(path, options = {}) ⇒ Root, Object

Parse XMI file

Parameters:

  • path (String)

    File path

  • options (Hash) (defaults to: {})

    Parsing options

Returns:

  • (Root, Object)

    Parsed XMI document



51
52
53
# File 'lib/xmi/parsing.rb', line 51

def parse_file(path, options = {})
  parse(File.read(path), options)
end

.supported_versionsArray<String>

Get supported XMI versions

Returns:

  • (Array<String>)


76
77
78
# File 'lib/xmi/parsing.rb', line 76

def supported_versions
  VersionRegistry.available_versions
end

.version_supported?(version) ⇒ Boolean

Check if a version is supported

Parameters:

  • version (String)

    Version string (e.g., “20131001”)

Returns:

  • (Boolean)


85
86
87
# File 'lib/xmi/parsing.rb', line 85

def version_supported?(version)
  supported_versions.include?(version)
end