Class: Ea::Sources::Xmi::TagBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/sources/xmi/tag_builder.rb

Overview

Extracts tagged values from the <xmi:Extension><tags><tag/> block. The xmi gem does not expose Sparx tags directly, so we parse the raw XML once and group tags by their modelElement attribute. Each tag's value is truncated at the first # (EA encodes notes after that marker).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xmi_path) ⇒ TagBuilder

Returns a new instance of TagBuilder.



16
17
18
# File 'lib/ea/sources/xmi/tag_builder.rb', line 16

def initialize(xmi_path)
  @xmi_path = xmi_path
end

Instance Attribute Details

#xmi_pathObject (readonly)

Returns the value of attribute xmi_path.



14
15
16
# File 'lib/ea/sources/xmi/tag_builder.rb', line 14

def xmi_path
  @xmi_path
end

Instance Method Details

#grouped_by_model_elementObject

Returns Hash=> Array



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ea/sources/xmi/tag_builder.rb', line 21

def grouped_by_model_element
  return {} if xmi_path.nil?

  @grouped ||= begin
    doc = Nokogiri::XML(File.read(xmi_path))
    # <tags><tag/></tags> lives inside per-element <element>
    # blocks within <xmi:Extension>. The element itself is in
    # no XML namespace; match by local-name to be safe.
    doc.xpath(%(//*[local-name()="tags"]/*[local-name()="tag"]))
      .each_with_object({}) do |node, acc|
      me = node["modelElement"]
      next unless me

      key = node["name"].to_s
      value = node["value"].to_s.split("#", 2).first
      next if key.empty?

      (acc[me] ||= []) << Ea::Model::TaggedValue.new(key: key, value: value)
    end
  end
end