Class: Ea::Svg::EaEmitter::Label::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/svg/ea_emitter/label/registry.rb

Overview

Dispatches a connector to the appropriate label renderer(s).

Rules:

- Any relationship with an applied stereotype renders
«stereotype» at the midpoint (Associations included —
«import» on a Package connector is a common case).
- Associations without a stereotype render EndLabel at
each positioned LLT/LRT box.
- Other relationship kinds without a stereotype render
nothing.

Open/closed: a new label kind registers here rather than forcing callers to edit case statements elsewhere.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_index:) ⇒ Registry

Returns a new instance of Registry.



23
24
25
# File 'lib/ea/svg/ea_emitter/label/registry.rb', line 23

def initialize(model_index:)
  @model_index = model_index
end

Instance Attribute Details

#model_indexObject (readonly)

Returns the value of attribute model_index.



21
22
23
# File 'lib/ea/svg/ea_emitter/label/registry.rb', line 21

def model_index
  @model_index
end

Instance Method Details

#association?(connector) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/ea/svg/ea_emitter/label/registry.rb', line 42

def association?(connector)
  rel = model_index ? model_index[connector.relationship_ref] : nil
  rel.is_a?(Ea::Model::Association)
end

#end_label?(connector) ⇒ Boolean

Returns true if the connector's relationship is an Association AND has no midpoint stereotype (the end-label path).

Returns:

  • (Boolean)


38
39
40
# File 'lib/ea/svg/ea_emitter/label/registry.rb', line 38

def end_label?(connector)
  association?(connector) && !midpoint?(connector)
end

#midpoint?(connector) ⇒ Boolean

Returns the formatted stereotype label when the connector should render at the midpoint, nil otherwise.

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/ea/svg/ea_emitter/label/registry.rb', line 29

def midpoint?(connector)
  MidpointLabel.new(canvas: nil, model_index: model_index,
                    font_family: nil, font_size: nil,
                    font_unit: nil).stereotype_label(connector)
end