Class: Xmi::Sparx::SparxRoot

Inherits:
Root show all
Defined in:
lib/xmi/sparx/root.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XmiIdentity::Attributes

included

Methods inherited from Lutaml::Model::Serializable

#type?

Class Method Details

.fix_encoding(xml_content) ⇒ String

Fix invalid UTF-8 encoding in the XML content.

Some EA-generated XMI files contain invalid UTF-8 byte sequences that would cause parsing failures. This method replaces invalid bytes with placeholder characters.

Parameters:

  • xml_content (String)

    The raw XML content

Returns:

  • (String)

    The XML content with valid UTF-8 encoding



48
49
50
51
52
53
54
# File 'lib/xmi/sparx/root.rb', line 48

def fix_encoding(xml_content)
  return xml_content if xml_content.valid_encoding?

  xml_content
    .encode("UTF-16be", invalid: :replace, replace: "?")
    .encode("UTF-8")
end

.parse_xml(xml_content) ⇒ SparxRoot

Parse XMI content into Ruby objects.

Uses the ParserPipeline for composable parsing steps: encoding fix → version detection → XML parsing → index building.

Parameters:

  • xml_content (String)

    The raw XMI XML content

Returns:

  • (SparxRoot)

    The parsed Ruby object with index built

See Also:



33
34
35
36
37
38
# File 'lib/xmi/sparx/root.rb', line 33

def parse_xml(xml_content)
  ctx = ParserPipeline.run(
    { xml: xml_content, root_class: self },
  )
  ctx[:root]
end

Instance Method Details

#build_indexSparx::Index

Build index for fast lookups

Returns:



62
63
64
# File 'lib/xmi/sparx/root.rb', line 62

def build_index
  @index = Index.new(self)
end

#indexSparx::Index

Access the index (builds on first access if needed)

Returns:



68
69
70
# File 'lib/xmi/sparx/root.rb', line 68

def index
  @index || build_index
end