Module: Ea::GuidFormat
- Defined in:
- lib/ea/guid_format.rb
Overview
Shared conversions between Sparx EA GUID strings and XMI identifier strings. No state, no I/O — same input always yields same output.
EA stores identifiers as {ABCD-1234-...} braced GUID strings.
XMI serializations use unbraced, dash→underscore forms prefixed
with EAID_ (most elements) or EAPK_ (packages at the model
root).
This module is shared across subsystems:
- Transformers::QeaToXmi (XMI export)
- Sources::Qea (model import / ID normalization)
- Qea::Factory (UML bridge reference resolution)
Previously each subsystem had its own inline gsub-based copy with subtle differences. Centralising here ensures one canonical conversion (DRY, MECE).
Constant Summary collapse
- SEP =
Braces and dashes both become underscores; collapse runs of consecutive underscores so
{AB-CD}→AB_CD(not_AB_CD_). /[-{}]/
Class Method Summary collapse
-
.connector_end_xmi_id(connector_xmi_id, side:) ⇒ String
Build a member-end xmi:id for one side of a connector.
-
.ea_guid_to_xmi_id(ea_guid, prefix: "EAID") ⇒ String?
E.g.
-
.return_parameter_xmi_id(operation_xmi_id) ⇒ String
Build the xmi:id for an operation's synthesized return parameter.
-
.strip_braces(ea_guid) ⇒ String
Strip braces from an EA GUID without adding prefix or converting dashes.
-
.xmi_id_to_ea_guid(xmi_id) ⇒ String?
E.g.
Class Method Details
.connector_end_xmi_id(connector_xmi_id, side:) ⇒ String
Build a member-end xmi:id for one side of a connector.
Sparx EA's convention: take the connector's GUID, drop the first
two hex characters of its first segment, and prepend src or
dst.
67 68 69 70 71 72 73 |
# File 'lib/ea/guid_format.rb', line 67 def connector_end_xmi_id(connector_xmi_id, side:) tag = side == :source ? "src" : "dst" body = connector_xmi_id.sub(/\A(?:EAID|EAPK)_/, "") first_segment, rest = body.split("_", 2) trimmed = first_segment.length > 2 ? first_segment[2..] : first_segment rest ? "EAID_#{tag}#{trimmed}_#{rest}" : "EAID_#{tag}#{trimmed}" end |
.ea_guid_to_xmi_id(ea_guid, prefix: "EAID") ⇒ String?
Returns e.g. "EAID_AB_CD_EF".
31 32 33 34 35 36 |
# File 'lib/ea/guid_format.rb', line 31 def ea_guid_to_xmi_id(ea_guid, prefix: "EAID") return nil if ea_guid.nil? || ea_guid.empty? clean = ea_guid.gsub(SEP, "_").gsub(/_+/, "_").gsub(/\A_/, "").gsub(/_\z/, "") "#{prefix}_#{clean}" end |
.return_parameter_xmi_id(operation_xmi_id) ⇒ String
Build the xmi:id for an operation's synthesized return parameter.
Sparx EA's convention: take the operation's own id and replace its
first GUID segment with RETURNID. An id carrying no further
segments has nothing to drop, so its only segment is kept. The
parameter's ea_guid is the braced form of this id, so callers
derive it with xmi_id_to_ea_guid rather than spelling the shape
a second time.
86 87 88 89 |
# File 'lib/ea/guid_format.rb', line 86 def return_parameter_xmi_id(operation_xmi_id) body = operation_xmi_id.sub(/\A(?:EAID|EAPK)_/, "") "EAID_RETURNID_#{body.split("_", 2).last}" end |
.strip_braces(ea_guid) ⇒ String
Strip braces from an EA GUID without adding prefix or converting dashes. Used where the caller needs just the bare GUID body (e.g. reference_resolver).
52 53 54 55 56 |
# File 'lib/ea/guid_format.rb', line 52 def strip_braces(ea_guid) return "" if ea_guid.nil? ea_guid.to_s.gsub(/[{}]/, "") end |
.xmi_id_to_ea_guid(xmi_id) ⇒ String?
Returns e.g. "AB-CD-EF".
40 41 42 43 44 45 |
# File 'lib/ea/guid_format.rb', line 40 def xmi_id_to_ea_guid(xmi_id) return nil if xmi_id.nil? || xmi_id.empty? body = xmi_id.sub(/\A(?:EAID|EAPK)_/, "") "{#{body.tr("_", "-")}}" end |