lutaml 0.9.9 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cdc354ae49059f9158e3bfb8d0e7813b6c61d0084fa42ed7071026a9e62d311
4
- data.tar.gz: 30c6683d8e22d2e1ded1b8ca53d3d63e5129025049314b036b678efb611f713e
3
+ metadata.gz: 9de4708a54b2e1e0cd6994dc7931e56711d2e257d1077f96003c4f8de6260c7e
4
+ data.tar.gz: 461a1f380240be81347038fac000ab836067599ac3485ed7d9e5ba61594f379f
5
5
  SHA512:
6
- metadata.gz: 1578a3589e20f92586cf4a60a6585ce5b758262a1112e3e5598e33c3209de72d477bf66b0fefd017e4633bd065ef93ed3fe37e2b55f60aae50a78203f299bcfa
7
- data.tar.gz: 72883f24b869448ac32f8724cb05cd5d24acf88ecbaa066bf084724f57ac116567266257f317b0e284e8ab081519eae6d8a2108915fb4e680076990b43339576
6
+ metadata.gz: 40e3e939f49e84407257d9d80cebe83e42ef74ba87d5763f5f0c245d445b857273bce8576f24948a4e0e836fa6df2a6f15980c7add173176910a3180da5b4477
7
+ data.tar.gz: 0c0c19132496f42ee08b6f9773d1807be9df6f4a3ada9ac49a3d846ee612742db086ca7e15494afbfee601f6ca6571ea532a28a2758f61c7576ba255602718ef
@@ -1,3 +1,3 @@
1
1
  module Lutaml
2
- VERSION = "0.9.9".freeze
2
+ VERSION = "0.9.11".freeze
3
3
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class AssociationDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def xmi_id
11
+ @model[:xmi_id]
12
+ end
13
+
14
+ def member_end
15
+ @model[:member_end]
16
+ end
17
+
18
+ def member_end_type
19
+ @model[:member_end_type]
20
+ end
21
+
22
+ def member_end_cardinality
23
+ ::Lutaml::XMI::CardinalityDrop.new(@model[:member_end_cardinality])
24
+ end
25
+
26
+ def member_end_attribute_name
27
+ @model[:member_end_attribute_name]
28
+ end
29
+
30
+ def member_end_xmi_id
31
+ @model[:member_end_xmi_id]
32
+ end
33
+
34
+ def owner_end
35
+ @model[:owner_end]
36
+ end
37
+
38
+ def owner_end_xmi_id
39
+ @model[:owner_end_xmi_id]
40
+ end
41
+
42
+ def definition
43
+ @model[:definition]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class AttributeDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def id
11
+ @model[:id]
12
+ end
13
+
14
+ def name
15
+ @model[:name]
16
+ end
17
+
18
+ def type
19
+ @model[:type]
20
+ end
21
+
22
+ def xmi_id
23
+ @model[:xmi_id]
24
+ end
25
+
26
+ def is_derived
27
+ @model[:is_derived]
28
+ end
29
+
30
+ def cardinality
31
+ ::Lutaml::XMI::CardinalityDrop.new(@model[:cardinality])
32
+ end
33
+
34
+ def definition
35
+ @model[:definition]
36
+ end
37
+
38
+ def association
39
+ @model[:association]
40
+ end
41
+
42
+ def type_ns
43
+ @model[:type_ns]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class CardinalityDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def min
11
+ @model["min"]
12
+ end
13
+
14
+ def max
15
+ @model["max"]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class ConstraintDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def name
11
+ @model[:name]
12
+ end
13
+
14
+ def type
15
+ @model[:type]
16
+ end
17
+
18
+ def weight
19
+ @model[:weight]
20
+ end
21
+
22
+ def status
23
+ @model[:status]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class DataTypeDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def xmi_id
11
+ @model[:xmi_id]
12
+ end
13
+
14
+ def name
15
+ @model[:name]
16
+ end
17
+
18
+ def attributes
19
+ @model[:attributes]&.map do |attribute|
20
+ ::Lutaml::XMI::AttributeDrop.new(attribute)
21
+ end
22
+ end
23
+
24
+ def operations
25
+ @model[:operations]&.map do |operation|
26
+ ::Lutaml::XMI::OperationDrop.new(operation)
27
+ end
28
+ end
29
+
30
+ def associations
31
+ @model[:associations]&.map do |association|
32
+ ::Lutaml::XMI::AssociationDrop.new(association)
33
+ end
34
+ end
35
+
36
+ def constraints
37
+ @model[:constraints]&.map do |constraint|
38
+ ::Lutaml::XMI::ConstraintDrop.new(constraint)
39
+ end
40
+ end
41
+
42
+ def is_abstract
43
+ @model[:is_abstract]
44
+ end
45
+
46
+ def definition
47
+ @model[:definition]
48
+ end
49
+
50
+ def stereotype
51
+ @model[:stereotype]
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class DiagramDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def xmi_id
11
+ @model[:xmi_id]
12
+ end
13
+
14
+ def name
15
+ @model[:name]
16
+ end
17
+
18
+ def definition
19
+ @model[:definition]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class EnumDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def xmi_id
11
+ @model[:xmi_id]
12
+ end
13
+
14
+ def name
15
+ @model[:name]
16
+ end
17
+
18
+ def values
19
+ @model[:values].map do |value|
20
+ ::Lutaml::XMI::EnumOwnedLiteralDrop.new(value)
21
+ end
22
+ end
23
+
24
+ def definition
25
+ @model[:definition]
26
+ end
27
+
28
+ def stereotype
29
+ @model[:stereotype]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class EnumOwnedLiteralDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def name
11
+ @model[:name]
12
+ end
13
+
14
+ def type
15
+ @model[:type]
16
+ end
17
+
18
+ def definition
19
+ @model[:definition]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class KlassDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def xmi_id
11
+ @model[:xmi_id]
12
+ end
13
+
14
+ def name
15
+ @model[:name]
16
+ end
17
+
18
+ def package
19
+ ::Lutaml::XMI::PackageDrop.new(@model[:package])
20
+ end
21
+
22
+ def type
23
+ @model[:type]
24
+ end
25
+
26
+ def attributes
27
+ @model[:attributes]&.map do |attribute|
28
+ ::Lutaml::XMI::AttributeDrop.new(attribute)
29
+ end
30
+ end
31
+
32
+ def associations
33
+ @model[:associations]&.map do |association|
34
+ ::Lutaml::XMI::AssociationDrop.new(association)
35
+ end
36
+ end
37
+
38
+ def operations
39
+ @model[:operations]&.map do |operation|
40
+ ::Lutaml::XMI::OperationDrop.new(operation)
41
+ end
42
+ end
43
+
44
+ def constraints
45
+ @model[:constraints]&.map do |constraint|
46
+ ::Lutaml::XMI::ConstraintDrop.new(constraint)
47
+ end
48
+ end
49
+
50
+ def is_abstract
51
+ @model[:is_abstract]
52
+ end
53
+
54
+ def definition
55
+ @model[:definition]
56
+ end
57
+
58
+ def stereotype
59
+ @model[:stereotype]
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class OperationDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ end
9
+
10
+ def id
11
+ @model[:id]
12
+ end
13
+
14
+ def xmi_id
15
+ @model[:xmi_id]
16
+ end
17
+
18
+ def name
19
+ @model[:name]
20
+ end
21
+
22
+ def definition
23
+ @model[:definition]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class PackageDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ @children_packages ||= packages.map do |pkg|
9
+ [pkg, pkg.packages, pkg.packages.map(&:children_packages)]
10
+ end.flatten.uniq
11
+ end
12
+
13
+ def xmi_id
14
+ @model[:xmi_id]
15
+ end
16
+
17
+ def name
18
+ @model[:name]
19
+ end
20
+
21
+ def klasses
22
+ @model[:classes].map do |klass|
23
+ ::Lutaml::XMI::KlassDrop.new(klass)
24
+ end
25
+ end
26
+ alias classes klasses
27
+
28
+ def enums
29
+ @model[:enums].map do |enum|
30
+ ::Lutaml::XMI::EnumDrop.new(enum)
31
+ end
32
+ end
33
+
34
+ def data_types
35
+ @model[:data_types].map do |data_type|
36
+ ::Lutaml::XMI::DataTypeDrop.new(data_type)
37
+ end
38
+ end
39
+
40
+ def diagrams
41
+ @model[:diagrams].map do |diagram|
42
+ ::Lutaml::XMI::DiagramDrop.new(diagram)
43
+ end
44
+ end
45
+
46
+ def packages
47
+ @model[:packages].map do |package|
48
+ ::Lutaml::XMI::PackageDrop.new(package)
49
+ end
50
+ end
51
+
52
+ def children_packages
53
+ @children_packages
54
+ end
55
+
56
+ def definition
57
+ @model[:definition]
58
+ end
59
+
60
+ def stereotype
61
+ @model[:stereotype]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class RootDrop < Liquid::Drop
6
+ def initialize(model) # rubocop:disable Lint/MissingSuper
7
+ @model = model
8
+ @children_packages ||= packages.map do |pkg|
9
+ [pkg, pkg.packages, pkg.packages.map(&:children_packages)]
10
+ end.flatten.uniq
11
+ end
12
+
13
+ def name
14
+ @model[:name]
15
+ end
16
+
17
+ def packages
18
+ @model[:packages].map do |package|
19
+ ::Lutaml::XMI::PackageDrop.new(package)
20
+ end
21
+ end
22
+
23
+ def children_packages
24
+ @children_packages
25
+ end
26
+ end
27
+ end
28
+ end
@@ -16,13 +16,44 @@ module Lutaml
16
16
  }.freeze
17
17
  attr_reader :xmi_cache, :xmi_root_model
18
18
 
19
- # @param xml [String] path to xml
20
- # @param options [Hash] options for parsing
21
- # @return [Lutaml::Uml::Document]
22
- def self.parse(xml, _options = {})
23
- xml_content = File.read(xml)
24
- xmi_model = Xmi::Sparx::SparxRoot.parse_xml(xml_content)
25
- new.parse(xmi_model)
19
+ class << self
20
+ # @param xml [String] path to xml
21
+ # @param options [Hash] options for parsing
22
+ # @return [Lutaml::Uml::Document]
23
+ def parse(xml, _options = {})
24
+ xmi_model = get_xmi_model(xml)
25
+ new.parse(xmi_model)
26
+ end
27
+
28
+ # @param xml [String] path to xml
29
+ # @return [Hash]
30
+ def serialize_xmi(xml)
31
+ xmi_model = get_xmi_model(xml)
32
+ new.serialize_xmi(xmi_model)
33
+ end
34
+
35
+ # @param xml [String] path to xml
36
+ # @return [Liquid::Drop]
37
+ def serialize_xmi_to_liquid(xml)
38
+ xmi_model = get_xmi_model(xml)
39
+ new.serialize_xmi_to_liquid(xmi_model)
40
+ end
41
+
42
+ # @param xml [String] path to xml
43
+ # @param name [String]
44
+ # @return [Hash]
45
+ def serialize_generalization_by_name(xml, name)
46
+ xmi_model = get_xmi_model(xml)
47
+ new.serialize_generalization_by_name(xmi_model, name)
48
+ end
49
+
50
+ private
51
+
52
+ # @param xml [String]
53
+ # @return [Shale::Mapper]
54
+ def get_xmi_model(xml)
55
+ Xmi::Sparx::SparxRoot.parse_xml(File.read(xml))
56
+ end
26
57
  end
27
58
 
28
59
  # @param xmi_model [Shale::Mapper]
@@ -30,7 +61,37 @@ module Lutaml
30
61
  def parse(xmi_model)
31
62
  @xmi_cache = {}
32
63
  @xmi_root_model = xmi_model
33
- ::Lutaml::Uml::Document.new(serialize_to_hash(xmi_model))
64
+ serialized_hash = serialize_xmi(xmi_model)
65
+
66
+ ::Lutaml::Uml::Document.new(serialized_hash)
67
+ end
68
+
69
+ # @param xmi_model [Shale::Mapper]
70
+ # return [Hash]
71
+ def serialize_xmi(xmi_model)
72
+ @xmi_cache = {}
73
+ @xmi_root_model = xmi_model
74
+ serialize_to_hash(xmi_model)
75
+ end
76
+
77
+ # @param xmi_model [Shale::Mapper]
78
+ # return [Liquid::Drop]
79
+ def serialize_xmi_to_liquid(xmi_model)
80
+ @xmi_cache = {}
81
+ @xmi_root_model = xmi_model
82
+ serialized_hash = serialize_xmi(xmi_model)
83
+
84
+ ::Lutaml::XMI::RootDrop.new(serialized_hash)
85
+ end
86
+
87
+ # @param xmi_model [Shale::Mapper]
88
+ # @param name [String]
89
+ # @return [Hash]
90
+ def serialize_generalization_by_name(xmi_model, name)
91
+ @xmi_cache = {}
92
+ @xmi_root_model = xmi_model
93
+ klass = find_klass_packaged_element_by_name(name)
94
+ serialize_generalization(klass)
34
95
  end
35
96
 
36
97
  private
@@ -105,6 +166,138 @@ module Lutaml
105
166
  end
106
167
  end
107
168
 
169
+ # @param klass [Shale::Mapper]
170
+ # # @return [Hash]
171
+ def serialize_generalization(klass)
172
+ general_hash, next_general_node_id = get_top_level_general_hash(klass)
173
+ return general_hash unless next_general_node_id
174
+
175
+ general_hash[:general] = serialize_generalization_attributes(
176
+ next_general_node_id,
177
+ )
178
+
179
+ general_hash
180
+ end
181
+
182
+ # @param klass [Shale::Mapper]
183
+ # @return [Array<Hash>]
184
+ def get_top_level_general_hash(klass) # rubocop:disable Metrics/AbcSize
185
+ general_hash, next_general_node_id = get_general_hash(klass.id)
186
+ general_hash[:name] = klass.name
187
+ general_hash[:type] = klass.type
188
+ general_hash[:definition] = lookup_general_documentation(klass.id)
189
+ general_hash[:stereotype] = doc_node_attribute_value(
190
+ klass.id, "stereotype"
191
+ )
192
+
193
+ # update_inherited_attributes(general_hash)
194
+ # update_gen_attributes(general_hash)
195
+
196
+ [general_hash, next_general_node_id]
197
+ end
198
+
199
+ def lookup_general_documentation(klass_id)
200
+ # lookup_attribute_documentation(klass_id) ||
201
+ # lookup_element_prop_documentation(klass_id)
202
+
203
+ lookup_element_prop_documentation(klass_id)
204
+ end
205
+
206
+ def update_gen_attributes(general_hash)
207
+ general_hash[:gen_attributes] = serialize_gen_attributes
208
+ end
209
+
210
+ def update_inherited_attributes(general_hash)
211
+ general_hash[:gml_attributes] = serialize_gml_attributes
212
+ general_hash[:core_attributes] = serialize_core_attributes
213
+ end
214
+
215
+ # @param xmi_id [String]
216
+ # @param model [Shale::Mapper]
217
+ # @return [Array<Hash>]
218
+ # @note get generalization node and its owned attributes
219
+ def serialize_generalization_attributes(general_id)
220
+ general_hash, next_general_node_id = get_general_hash(general_id)
221
+
222
+ if next_general_node_id
223
+ general_hash[:general] = serialize_generalization_attributes(
224
+ next_general_node_id,
225
+ )
226
+ end
227
+
228
+ general_hash
229
+ end
230
+
231
+ # @param xmi_id [String]
232
+ # @return [Shale::Mapper]
233
+ def get_general_node(xmi_id)
234
+ find_packaged_element_by_id(xmi_id)
235
+ end
236
+
237
+ # @param general_node [Shale::Mapper]
238
+ # # @return [Hash]
239
+ def get_general_attributes(general_node)
240
+ attrs = serialize_class_attributes(general_node, with_assoc: true)
241
+ attrs.sort_by { |i| i[:name] }
242
+ end
243
+
244
+ # @param general_node [Shale::Mapper]
245
+ # @return [String]
246
+ def get_next_general_node_id(general_node)
247
+ general_node.generalization.first&.general
248
+ end
249
+
250
+ # @param general_id [String]
251
+ # @return [Array<Hash>]
252
+ def get_general_hash(general_id)
253
+ general_node = get_general_node(general_id)
254
+ general_node_attrs = get_general_attributes(general_node)
255
+ general_upper_klass = find_upper_level_packaged_element(general_id)
256
+ next_general_node_id = get_next_general_node_id(general_node)
257
+
258
+ [
259
+ {
260
+ general_id: general_id,
261
+ general_name: general_node.name,
262
+ general_attributes: general_node_attrs,
263
+ general_upper_klass: general_upper_klass,
264
+ general: {},
265
+ },
266
+ next_general_node_id,
267
+ ]
268
+ end
269
+
270
+ # @param id [String]
271
+ # @return [Shale::Mapper]
272
+ def find_packaged_element_by_id(id)
273
+ all_packaged_elements.find { |e| e.id == id }
274
+ end
275
+
276
+ # @param id [String]
277
+ # @return [Shale::Mapper]
278
+ def find_upper_level_packaged_element(klass_id)
279
+ upper_klass = all_packaged_elements.find do |e|
280
+ e.packaged_element.find { |pe| pe.id == klass_id }
281
+ end
282
+ upper_klass&.name
283
+ end
284
+
285
+ # @param name [String]
286
+ # @return [Shale::Mapper]
287
+ def find_klass_packaged_element_by_name(name)
288
+ all_packaged_elements.find do |e|
289
+ e.type?("uml:Class") && e.name == name
290
+ end
291
+ end
292
+
293
+ # @param name [String]
294
+ # @return [Shale::Mapper]
295
+ def find_packaged_element_by_name(name)
296
+ all_packaged_elements.find do |e|
297
+ e.name == name
298
+ end
299
+ end
300
+
108
301
  # @param package [Shale::Mapper]
109
302
  # @return [Array<Hash>]
110
303
  # @note xpath ./packagedElement[@xmi:type="uml:Enumeration"]
@@ -226,9 +419,9 @@ module Lutaml
226
419
  # @return [Shale::Mapper]
227
420
  # @note xpath %(//connector[@xmi:idref="#{link_id}"])
228
421
  def fetch_connector(link_id)
229
- @xmi_root_model.extension.connectors.connector.select do |con|
422
+ @xmi_root_model.extension.connectors.connector.find do |con|
230
423
  con.idref == link_id
231
- end.first
424
+ end
232
425
  end
233
426
 
234
427
  # @param link_id [String]
@@ -428,9 +621,9 @@ module Lutaml
428
621
  all_elements = all_packaged_elements
429
622
 
430
623
  owned_attributes = all_elements.map(&:owned_attribute).flatten
431
- oa = owned_attributes.select do |a|
624
+ oa = owned_attributes.find do |a|
432
625
  !!a.association && a.uml_type && a.uml_type.idref == xmi_id
433
- end.first
626
+ end
434
627
 
435
628
  if oa
436
629
  cardinality = cardinality_min_max_value(
@@ -446,37 +639,104 @@ module Lutaml
446
639
  # @return [Shale::Mapper]
447
640
  # @note xpath %(//element[@xmi:idref="#{klass['xmi:id']}"])
448
641
  def fetch_element(klass_id)
449
- @xmi_root_model.extension.elements.element.select do |e|
642
+ @xmi_root_model.extension.elements.element.find do |e|
450
643
  e.idref == klass_id
451
- end.first
644
+ end
452
645
  end
453
646
 
454
647
  # @param klass [Shale::Mapper]
648
+ # @param with_assoc [Boolean]
455
649
  # @return [Array<Hash>]
456
650
  # @note xpath .//ownedAttribute[@xmi:type="uml:Property"]
457
- def serialize_class_attributes(klass)
651
+ def serialize_class_attributes(klass, with_assoc: false)
458
652
  klass.owned_attribute.select { |attr| attr.type?("uml:Property") }
459
653
  .map do |oa|
460
- uml_type = oa.uml_type
461
- uml_type_idref = uml_type.idref if uml_type
654
+ if with_assoc || oa.association.nil?
655
+ attrs = build_class_attributes(oa)
462
656
 
463
- if oa.association.nil?
464
- {
465
- id: oa.id,
466
- name: oa.name,
467
- type: lookup_entity_name(uml_type_idref) || uml_type_idref,
468
- xmi_id: uml_type_idref,
469
- is_derived: oa.is_derived,
470
- cardinality: cardinality_min_max_value(
471
- oa.lower_value&.value,
472
- oa.upper_value&.value,
473
- ),
474
- definition: lookup_attribute_documentation(oa.id),
475
- }
657
+ if with_assoc && oa.association
658
+ attrs[:association] = oa.association
659
+ attrs[:definition] = loopup_assoc_def(oa.association)
660
+ attrs[:type_ns] = get_ns_by_type(attrs[:type])
661
+ end
662
+
663
+ attrs
476
664
  end
477
665
  end.compact
478
666
  end
479
667
 
668
+ def loopup_assoc_def(association)
669
+ connector = fetch_connector(association)
670
+ connector&.documentation&.value
671
+ end
672
+
673
+ # @return [Array<Hash>]
674
+ def serialize_gml_attributes
675
+ element = find_packaged_element_by_name("_Feature")
676
+ attrs = serialize_class_attributes(element, with_assoc: true)
677
+ attrs.each { |attr| attr[:upper_klass] = "gml" }
678
+ end
679
+
680
+ # @return [Array<Hash>]
681
+ def serialize_core_attributes
682
+ element = find_packaged_element_by_name("_CityObject")
683
+ attrs = serialize_class_attributes(element, with_assoc: false)
684
+ attrs.each { |attr| attr[:upper_klass] = "core" }
685
+ end
686
+
687
+ # @return [Array<Hash>]
688
+ def select_gen_attributes
689
+ element = find_packaged_element_by_name("gen")
690
+ gen_attr_element = find_packaged_element_by_name("_genericAttribute")
691
+
692
+ element.packaged_element.select do |e|
693
+ e.type?("uml:Class") &&
694
+ e.generalization&.first&.general == gen_attr_element.id
695
+ end
696
+ end
697
+
698
+ # @return [Array<Hash>]
699
+ def serialize_gen_attributes
700
+ klasses = select_gen_attributes
701
+
702
+ klasses.map do |klass|
703
+ attr = serialize_class_attributes(klass, with_assoc: false)
704
+ attr.first[:name] = klass.name
705
+ attr.first[:type] = "gen:#{klass.name}"
706
+ attr.first[:upper_klass] = "gen"
707
+ attr
708
+ end.flatten!
709
+ end
710
+
711
+ # @param type [String]
712
+ # @return [String]
713
+ def get_ns_by_type(type)
714
+ return unless type
715
+
716
+ p = find_klass_packaged_element_by_name(type)
717
+ find_upper_level_packaged_element(p.id)
718
+ end
719
+
720
+ # @param klass_id [String]
721
+ # @return [Array<Hash>]
722
+ def build_class_attributes(owned_attr) # rubocop:disable Metrics/MethodLength
723
+ uml_type = owned_attr.uml_type
724
+ uml_type_idref = uml_type.idref if uml_type
725
+
726
+ {
727
+ id: owned_attr.id,
728
+ name: owned_attr.name,
729
+ type: lookup_entity_name(uml_type_idref) || uml_type_idref,
730
+ xmi_id: uml_type_idref,
731
+ is_derived: owned_attr.is_derived,
732
+ cardinality: cardinality_min_max_value(
733
+ owned_attr.lower_value&.value,
734
+ owned_attr.upper_value&.value,
735
+ ),
736
+ definition: lookup_attribute_documentation(owned_attr.id),
737
+ }
738
+ end
739
+
480
740
  # @param min [String]
481
741
  # @param max [String]
482
742
  # @return [Hash]
@@ -533,6 +793,18 @@ module Lutaml
533
793
  attribute_node&.documentation&.value
534
794
  end
535
795
 
796
+ # @param xmi_id [String]
797
+ # @return [String]
798
+ def lookup_element_prop_documentation(xmi_id)
799
+ element_node = @xmi_root_model.extension.elements.element.find do |e|
800
+ e.idref == xmi_id
801
+ end
802
+
803
+ return unless element_node&.properties
804
+
805
+ element_node&.properties&.documentation
806
+ end
807
+
536
808
  # @param xmi_id [String]
537
809
  # @return [String]
538
810
  def lookup_entity_name(xmi_id)
data/lib/lutaml/xmi.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  require "lutaml/xmi/version"
2
2
  require "lutaml/xmi/parsers/xml"
3
+ require "liquid"
4
+
5
+ Dir["#{File.dirname(__FILE__)}/xmi/liquid_drops/**/*.rb"].sort.each do |f|
6
+ require f
7
+ end
3
8
 
4
9
  module Lutaml
5
10
  module XMI
data/lutaml.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.required_ruby_version = ">= 2.7.0"
31
31
 
32
+ spec.add_runtime_dependency "liquid"
32
33
  spec.add_runtime_dependency "expressir", "~> 1.3"
33
34
  spec.add_runtime_dependency "hashie", "~> 4.1.0"
34
35
  spec.add_runtime_dependency "htmlentities"
@@ -45,4 +46,4 @@ Gem::Specification.new do |spec|
45
46
  spec.add_development_dependency "rspec", "~> 3.11"
46
47
  spec.add_development_dependency "rubocop", "~> 1.58"
47
48
  spec.add_development_dependency "rubocop-performance", "~> 1.19"
48
- end
49
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-12 00:00:00.000000000 Z
11
+ date: 2024-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: liquid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: expressir
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -354,6 +368,18 @@ files:
354
368
  - lib/lutaml/version.rb
355
369
  - lib/lutaml/xmi.rb
356
370
  - lib/lutaml/xmi/README.adoc
371
+ - lib/lutaml/xmi/liquid_drops/association_drop.rb
372
+ - lib/lutaml/xmi/liquid_drops/attribute_drop.rb
373
+ - lib/lutaml/xmi/liquid_drops/cardinality_drop.rb
374
+ - lib/lutaml/xmi/liquid_drops/constraint_drop.rb
375
+ - lib/lutaml/xmi/liquid_drops/data_type_drop.rb
376
+ - lib/lutaml/xmi/liquid_drops/diagram_drop.rb
377
+ - lib/lutaml/xmi/liquid_drops/enum_drop.rb
378
+ - lib/lutaml/xmi/liquid_drops/enum_owned_literal_drop.rb
379
+ - lib/lutaml/xmi/liquid_drops/klass_drop.rb
380
+ - lib/lutaml/xmi/liquid_drops/operation_drop.rb
381
+ - lib/lutaml/xmi/liquid_drops/package_drop.rb
382
+ - lib/lutaml/xmi/liquid_drops/root_drop.rb
357
383
  - lib/lutaml/xmi/parsers/xml.rb
358
384
  - lib/lutaml/xmi/version.rb
359
385
  - lib/lutaml/xml.rb