Class: Archimate::FileFormats::ModelExchangeFileWriter30
Instance Attribute Summary
#model
Attributes inherited from Writer
#model
Instance Method Summary
collapse
-
#font_style_string(font) ⇒ Object
-
#initialize(model) ⇒ ModelExchangeFileWriter30
constructor
A new instance of ModelExchangeFileWriter30.
-
#meff_type(el_type) ⇒ Object
-
#model_attrs ⇒ Object
-
#relationship_attributes(relationship) ⇒ Object
-
#serialize_connection(xml, sc) ⇒ Object
-
#serialize_diagram(xml, diagram) ⇒ Object
-
#serialize_item(xml, item) ⇒ Object
-
#serialize_label(xml, str, tag = :name) ⇒ Object
-
#serialize_model(xml) ⇒ Object
-
#serialize_organization_root(xml, organizations) ⇒ Object
-
#serialize_property(xml, property) ⇒ Object
-
#serialize_property_defs(xml) ⇒ Object
-
#serialize_view_node(xml, view_node, x_offset = 0, y_offset = 0) ⇒ Object
-
#serialize_views(xml) ⇒ Object
-
#view_node_attrs(view_node, x_offset = 0, y_offset = 0) ⇒ Object
#elementbase, #identifier, #model_namespaces, #serialize_color, #serialize_element, #serialize_elements, #serialize_font, #serialize_location, #serialize_organization, #serialize_organization_body, #serialize_properties, #serialize_relationship, #serialize_relationships, #serialize_style, #text_proc, #write
Methods inherited from Writer
#remove_nil_values, #serialize, write
Constructor Details
Returns a new instance of ModelExchangeFileWriter30.
7
8
9
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 7
def initialize(model)
super
end
|
Instance Method Details
#font_style_string(font) ⇒ Object
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 124
def font_style_string(font)
case font&.style
when 1
"italic"
when 2
"bold"
when 3
"bold italic"
end
end
|
#meff_type(el_type) ⇒ Object
148
149
150
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 148
def meff_type(el_type)
el_type.sub(/^/, "")
end
|
#model_attrs ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 11
def model_attrs
remove_nil_values(
model_namespaces.merge(
"xsi:schemaLocation" => model.schema_locations.join(" "),
"identifier" => identifier(model.id),
"version" => model.version
)
)
end
|
#relationship_attributes(relationship) ⇒ Object
46
47
48
49
50
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 46
def relationship_attributes(relationship)
attrs = super
attrs["accessType"] = relationship.access_type if relationship.access_type
attrs
end
|
#serialize_connection(xml, sc) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 135
def serialize_connection(xml, sc)
xml.connection(
identifier: identifier(sc.id),
relationshipRef: identifier(sc.relationship),
"xsi:type": sc.type,
source: identifier(sc.source),
target: identifier(sc.target)
) do
serialize(xml, sc.style)
serialize(xml, sc.bendpoints)
end
end
|
#serialize_diagram(xml, diagram) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 78
def serialize_diagram(xml, diagram)
xml.view(
remove_nil_values(
identifier: identifier(diagram.id),
"xsi:type": diagram.type,
viewpoint: diagram.viewpoint_type
)
) do
elementbase(xml, diagram)
serialize(xml, diagram.nodes)
serialize(xml, diagram.connections)
end
end
|
#serialize_item(xml, item) ⇒ Object
59
60
61
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 59
def serialize_item(xml, item)
xml.item(identifierRef: identifier(item))
end
|
#serialize_label(xml, str, tag = :name) ⇒ Object
40
41
42
43
44
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 40
def serialize_label(xml, str, tag = :name)
return if str.nil? || str.strip.empty?
name_attrs = str.lang && !str.lang.empty? ? {"xml:lang" => str.lang} : {}
xml.send(tag, name_attrs) { xml.text text_proc(str) }
end
|
#serialize_model(xml) ⇒ Object
#serialize_organization_root(xml, organizations) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 52
def serialize_organization_root(xml, organizations)
return unless organizations && organizations.size > 0
xml.organizations do
serialize_organization_body(xml, organizations[0])
end
end
|
#serialize_property(xml, property) ⇒ Object
63
64
65
66
67
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 63
def serialize_property(xml, property)
xml.property("propertyDefinitionRef" => property.property_definition.id) do
ModelExchangeFile::XmlLangString.new(property.value, :value).serialize(xml)
end
end
|
#serialize_property_defs(xml) ⇒ Object
35
36
37
38
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 35
def serialize_property_defs(xml)
return if model.property_definitions.empty?
ModelExchangeFile::XmlPropertyDefinitions.new(model.property_definitions).serialize(xml)
end
|
#serialize_view_node(xml, view_node, x_offset = 0, y_offset = 0) ⇒ Object
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 113
def serialize_view_node(xml, view_node, x_offset = 0, y_offset = 0)
attrs = view_node_attrs(view_node, x_offset, y_offset)
xml.node(attrs) do
serialize_label(xml, view_node.name, :label)
serialize(xml, view_node.style) if view_node.style
view_node.nodes.each do |c|
serialize_view_node(xml, c) end
end
end
|
#serialize_views(xml) ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 69
def serialize_views(xml)
return if model.diagrams.empty?
xml.views do
xml.diagrams {
serialize(xml, model.diagrams)
}
end
end
|
#view_node_attrs(view_node, x_offset = 0, y_offset = 0) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/archimate/file_formats/model_exchange_file_writer_30.rb', line 92
def view_node_attrs(view_node, x_offset = 0, y_offset = 0)
attrs = {
identifier: identifier(view_node.id),
elementRef: nil,
"xsi:type" => view_node.type,
"x" => view_node.bounds ? (view_node.bounds&.x + x_offset).round : nil,
"y" => view_node.bounds ? (view_node.bounds&.y + y_offset).round : nil,
"w" => view_node.bounds&.width&.round,
"h" => view_node.bounds&.height&.round
}
if view_node.archimate_element
attrs[:elementRef] = identifier(view_node.archimate_element)
elsif view_node.model
attrs[:elementRef] = view_node.model
attrs[:type] = "model"
end
remove_nil_values(attrs)
end
|