Class: Archimate::DataModel::Element

Inherits:
Object
  • Object
show all
Includes:
Comparison
Defined in:
lib/archimate/data_model/element.rb

Overview

TODO:

Possible Make this abstract with concrete implementations for all valid element types

A base element type that can be extended by concrete ArchiMate types.

Note that ElementType is abstract, so one must have derived types of this type. This is indicated in xml by having a tag name of element and an attribute of xsi:type=“BusinessRole” where BusinessRole is a derived type from [ElementType].

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Comparison

#==, #[], #dig, #each, #hash, included, #pretty_print, #to_h

Constructor Details

#initialize(id:, name:, documentation: nil, type: nil, properties: []) ⇒ Element

Returns a new instance of Element.



38
39
40
41
42
43
44
# File 'lib/archimate/data_model/element.rb', line 38

def initialize(id:, name:, documentation: nil, type: nil, properties: [])
  @id = id
  @name = name
  @documentation = documentation
  @type = type
  @properties = properties
end

Instance Attribute Details

#documentationPreservedLangString, NilClass

Returns:



25
# File 'lib/archimate/data_model/element.rb', line 25

model_attr :documentation, writable: true

#idString (readonly)

Returns:

  • (String)


19
# File 'lib/archimate/data_model/element.rb', line 19

model_attr :id

#nameLangString, NilClass (readonly)

Returns:



22
# File 'lib/archimate/data_model/element.rb', line 22

model_attr :name

#propertiesArray<Property> (readonly)

Returns:



36
# File 'lib/archimate/data_model/element.rb', line 36

model_attr :properties

#typeString, NilClass (readonly)

Returns:

  • (String, NilClass)


33
# File 'lib/archimate/data_model/element.rb', line 33

model_attr :type

Instance Method Details

#diagramsObject

Diagrams that this element is referenced in.



55
56
57
58
59
# File 'lib/archimate/data_model/element.rb', line 55

def diagrams
  @diagrams ||= in_model.diagrams.select do |diagram|
    diagram.element_ids.include?(id)
  end
end

#layerObject



50
51
52
# File 'lib/archimate/data_model/element.rb', line 50

def layer
  Layers.for_element(type)
end

#merge(element) ⇒ Object

Copy any attributes/docs, etc. from each of the others into the original.

1. Child `label`s with different `xml:lang` attribute values
2. Child `documentation` (and different `xml:lang` attribute values)
3. Child `properties`
4. Any other elements


73
74
75
76
77
78
# File 'lib/archimate/data_model/element.rb', line 73

def merge(element)
  super
  element.diagrams.each { |diagram| diagram.replace(element, self) }
  element.relationships.each { |relationship| relationship.replace(element, self) }
  element.organization.remove(element.id)
end

#relationshipsObject

Relationships that this element is referenced in.



62
63
64
65
66
# File 'lib/archimate/data_model/element.rb', line 62

def relationships
  @relationships ||= in_model.relationships.select do |relationship|
    relationship.source == id || relationship.target == id
  end
end

#to_sObject



46
47
48
# File 'lib/archimate/data_model/element.rb', line 46

def to_s
  Archimate::Color.layer_color(layer, "#{type}<#{id}>[#{name}]")
end