Class: Ea::Svg::EaEmitter::Element::AttributeLineBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/svg/ea_emitter/element/attribute_line_builder.rb

Overview

Builds the text representation of a single property line for the attribute compartment. Encapsulates the four EA rendering rules:

1. Visibility marker (+, -, #, ~).
2. Namespace prefix on properties inherited from a
 classifier in a different package ("core::mimeType").
3. Primitive type name stripping ("xs::double" → "double").
4. Multiplicity shorthand ("[2..2]" → "[2]") and
 `{ordered}` modifier.

Stateless: each call returns a fresh line String. Pass a Lookup to enable cross-classifier resolution (namespace prefix). Without a lookup, the line is rendered as-is (backwards-compatible).

Constant Summary collapse

PRIMITIVE_TYPES =

XSD primitive types whose namespace prefix EA drops in the rendered attribute line. The full set is not yet reverse-engineered — leave empty for now so we never wrongly strip a prefix. TODO-D 47 will populate this once verified per-diagram.

Set.new([]).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property, host: nil, lookup: nil) ⇒ AttributeLineBuilder

property - the Ea::Model::Property to render host - the Ea::Model::Classifier whose compartment we're rendering (determines "inherited" status) lookup - object responding to #call(id) -> Classifier used to resolve the property's declaring classifier (defaults to no lookup).



38
39
40
41
42
# File 'lib/ea/svg/ea_emitter/element/attribute_line_builder.rb', line 38

def initialize(property, host: nil, lookup: nil)
  @property = property
  @host = host
  @lookup = lookup
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



30
31
32
# File 'lib/ea/svg/ea_emitter/element/attribute_line_builder.rb', line 30

def host
  @host
end

#lookupObject (readonly)

Returns the value of attribute lookup.



30
31
32
# File 'lib/ea/svg/ea_emitter/element/attribute_line_builder.rb', line 30

def lookup
  @lookup
end

#propertyObject (readonly)

Returns the value of attribute property.



30
31
32
# File 'lib/ea/svg/ea_emitter/element/attribute_line_builder.rb', line 30

def property
  @property
end

Instance Method Details

#to_sObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/ea/svg/ea_emitter/element/attribute_line_builder.rb', line 44

def to_s
  parts = ["#{visibility_marker} "]
  parts << namespaced_name
  type_str = formatted_type
  parts << ": #{type_str}" unless type_str.empty?
  mult = multiplicity
  parts << " #{mult}" unless mult.empty?
  parts << " = #{property.default_value}" if property.default_value && !property.default_value.to_s.empty?
  parts.join.rstrip
end