Class: Xmi::Sparx::Index
- Inherits:
-
Object
- Object
- Xmi::Sparx::Index
- Defined in:
- lib/xmi/sparx/index.rb
Overview
Builds all commonly needed indexes from a parsed SparxRoot in a single targeted walk, avoiding the generic map_id_name approach that visits every attribute of every node.
Indexes built:
-
id_name_map: { xmi_id => name } for all nodes with both id and name
-
packaged_elements: flat array of all PackagedElement instances
-
packaged_by_id: { xmi_id => PackagedElement }
-
packaged_by_type: { “uml:Class” => […], “uml:Package” => […], … }
-
upper_level_map: { xmi_id => parent PackagedElement }
-
elements_by_idref: { idref => Extension::Element::Element }
-
connectors_by_idref: { idref => Connector::Connector }
-
attributes_by_idref: { idref => Extension::Element::Attribute }
-
owned_attrs_by_type_idref: { type_idref => [OwnedAttribute, …] }
Constant Summary collapse
- PackagedElement =
::Xmi::Uml::PackagedElement
Instance Attribute Summary collapse
-
#attributes_by_idref ⇒ Object
readonly
Returns the value of attribute attributes_by_idref.
-
#connectors_by_idref ⇒ Object
readonly
Returns the value of attribute connectors_by_idref.
-
#elements_by_idref ⇒ Object
readonly
Returns the value of attribute elements_by_idref.
-
#id_name_map ⇒ Object
readonly
Returns the value of attribute id_name_map.
-
#owned_attrs_by_type_idref ⇒ Object
readonly
Returns the value of attribute owned_attrs_by_type_idref.
-
#packaged_by_id ⇒ Object
readonly
Returns the value of attribute packaged_by_id.
-
#packaged_by_type ⇒ Object
readonly
Returns the value of attribute packaged_by_type.
-
#packaged_elements ⇒ Object
readonly
Returns the value of attribute packaged_elements.
-
#upper_level_map ⇒ Object
readonly
Returns the value of attribute upper_level_map.
Instance Method Summary collapse
-
#find_attribute(idref) ⇒ Xmi::Sparx::Element::Attribute?
Find extension attribute by idref.
-
#find_connector(idref) ⇒ Xmi::Sparx::Connector::Connector?
Find connector by idref.
-
#find_element(idref) ⇒ Xmi::Sparx::Element::Element?
Find extension element by idref.
-
#find_owned_attrs_by_type(type_idref) ⇒ Array<Xmi::Uml::OwnedAttribute>
Find owned attributes whose uml_type.idref matches.
-
#find_packaged_by_name_and_types(name, types) ⇒ Xmi::Uml::PackagedElement?
Find first packaged element by name and allowed types.
-
#find_packaged_element(id) ⇒ Xmi::Uml::PackagedElement?
Find packaged element by XMI ID.
-
#find_parent(id) ⇒ Xmi::Uml::PackagedElement?
Find parent of a packaged element.
-
#initialize(root) ⇒ Index
constructor
A new instance of Index.
-
#lookup_name(xmi_id) ⇒ String?
Lookup name by XMI ID.
-
#packaged_elements_of_type(type) ⇒ Array<Xmi::Uml::PackagedElement>
Find packaged elements by UML type.
Constructor Details
#initialize(root) ⇒ Index
Returns a new instance of Index.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/xmi/sparx/index.rb', line 28 def initialize(root) @id_name_map = {} @packaged_elements = [] @packaged_by_id = {} @packaged_by_type = {} @upper_level_map = {} @elements_by_idref = {} @connectors_by_idref = {} @attributes_by_idref = {} @owned_attrs_by_type_idref = {} build(root) freeze end |
Instance Attribute Details
#attributes_by_idref ⇒ Object (readonly)
Returns the value of attribute attributes_by_idref.
20 21 22 |
# File 'lib/xmi/sparx/index.rb', line 20 def attributes_by_idref @attributes_by_idref end |
#connectors_by_idref ⇒ Object (readonly)
Returns the value of attribute connectors_by_idref.
20 21 22 |
# File 'lib/xmi/sparx/index.rb', line 20 def connectors_by_idref @connectors_by_idref end |
#elements_by_idref ⇒ Object (readonly)
Returns the value of attribute elements_by_idref.
20 21 22 |
# File 'lib/xmi/sparx/index.rb', line 20 def elements_by_idref @elements_by_idref end |
#id_name_map ⇒ Object (readonly)
Returns the value of attribute id_name_map.
20 21 22 |
# File 'lib/xmi/sparx/index.rb', line 20 def id_name_map @id_name_map end |
#owned_attrs_by_type_idref ⇒ Object (readonly)
Returns the value of attribute owned_attrs_by_type_idref.
20 21 22 |
# File 'lib/xmi/sparx/index.rb', line 20 def owned_attrs_by_type_idref @owned_attrs_by_type_idref end |
#packaged_by_id ⇒ Object (readonly)
Returns the value of attribute packaged_by_id.
20 21 22 |
# File 'lib/xmi/sparx/index.rb', line 20 def packaged_by_id @packaged_by_id end |
#packaged_by_type ⇒ Object (readonly)
Returns the value of attribute packaged_by_type.
20 21 22 |
# File 'lib/xmi/sparx/index.rb', line 20 def packaged_by_type @packaged_by_type end |
#packaged_elements ⇒ Object (readonly)
Returns the value of attribute packaged_elements.
20 21 22 |
# File 'lib/xmi/sparx/index.rb', line 20 def packaged_elements @packaged_elements end |
#upper_level_map ⇒ Object (readonly)
Returns the value of attribute upper_level_map.
20 21 22 |
# File 'lib/xmi/sparx/index.rb', line 20 def upper_level_map @upper_level_map end |
Instance Method Details
#find_attribute(idref) ⇒ Xmi::Sparx::Element::Attribute?
Find extension attribute by idref
81 82 83 |
# File 'lib/xmi/sparx/index.rb', line 81 def find_attribute(idref) @attributes_by_idref[idref] end |
#find_connector(idref) ⇒ Xmi::Sparx::Connector::Connector?
Find connector by idref
74 75 76 |
# File 'lib/xmi/sparx/index.rb', line 74 def find_connector(idref) @connectors_by_idref[idref] end |
#find_element(idref) ⇒ Xmi::Sparx::Element::Element?
Find extension element by idref
67 68 69 |
# File 'lib/xmi/sparx/index.rb', line 67 def find_element(idref) @elements_by_idref[idref] end |
#find_owned_attrs_by_type(type_idref) ⇒ Array<Xmi::Uml::OwnedAttribute>
Find owned attributes whose uml_type.idref matches
88 89 90 |
# File 'lib/xmi/sparx/index.rb', line 88 def find_owned_attrs_by_type(type_idref) @owned_attrs_by_type_idref[type_idref] || [] end |
#find_packaged_by_name_and_types(name, types) ⇒ Xmi::Uml::PackagedElement?
Find first packaged element by name and allowed types
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/xmi/sparx/index.rb', line 103 def find_packaged_by_name_and_types(name, types) types.each do |type| elements = @packaged_by_type[type] next unless elements found = elements.find { |e| e.name == name } return found if found end nil end |
#find_packaged_element(id) ⇒ Xmi::Uml::PackagedElement?
Find packaged element by XMI ID
53 54 55 |
# File 'lib/xmi/sparx/index.rb', line 53 def find_packaged_element(id) @packaged_by_id[id] end |
#find_parent(id) ⇒ Xmi::Uml::PackagedElement?
Find parent of a packaged element
60 61 62 |
# File 'lib/xmi/sparx/index.rb', line 60 def find_parent(id) @upper_level_map[id] end |
#lookup_name(xmi_id) ⇒ String?
Lookup name by XMI ID
46 47 48 |
# File 'lib/xmi/sparx/index.rb', line 46 def lookup_name(xmi_id) @id_name_map[xmi_id] end |
#packaged_elements_of_type(type) ⇒ Array<Xmi::Uml::PackagedElement>
Find packaged elements by UML type
95 96 97 |
# File 'lib/xmi/sparx/index.rb', line 95 def packaged_elements_of_type(type) @packaged_by_type[type] || [] end |