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



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/xmi/parsing.rb', line 57

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
# File 'lib/xmi/parsing.rb', line 29

def parse(xml, options = {})
  xml_content = xml.is_a?(String) ? xml : xml.read

  ctx = {
    xml: xml_content,
    root_class: options[:model_class] || Root,
  }
  register = explicit_register(options)
  ctx[:register] = register if register

  ParserPipeline.run(ctx)[:root]
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



48
49
50
# File 'lib/xmi/parsing.rb', line 48

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

.supported_versionsArray<String>

Get supported XMI versions

Returns:

  • (Array<String>)


73
74
75
# File 'lib/xmi/parsing.rb', line 73

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)


82
83
84
# File 'lib/xmi/parsing.rb', line 82

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