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.
Class Method Summary collapse
-
.detect_version(xml) ⇒ Hash
Detect XMI version without full parsing.
-
.parse(xml, options = {}) ⇒ Root, Object
Parse XMI with automatic version detection.
-
.parse_file(path, options = {}) ⇒ Root, Object
Parse XMI file.
-
.supported_versions ⇒ Array<String>
Get supported XMI versions.
-
.version_supported?(version) ⇒ Boolean
Check if a version is supported.
Class Method Details
.detect_version(xml) ⇒ Hash
Detect XMI version without full parsing
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
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, = {}) xml_content = xml.respond_to?(:read) ? xml.read : xml.to_s Xmi.init_versioning! unless Xmi.versioning_initialized? register = determine_register(xml_content, ) model_class = [: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
51 52 53 |
# File 'lib/xmi/parsing.rb', line 51 def parse_file(path, = {}) parse(File.read(path), ) end |
.supported_versions ⇒ Array<String>
Get supported XMI versions
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
85 86 87 |
# File 'lib/xmi/parsing.rb', line 85 def version_supported?(version) supported_versions.include?(version) end |