lutaml 0.9.19 → 0.9.21

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: a1741d3f305d796167f5f6927857b8d59141e3eeae8073c37db589d9e341424e
4
- data.tar.gz: a35f626e98174a80214904da6f979fac35d4b58fa150908e35ba68ddf2000278
3
+ metadata.gz: aa2001799c50e05bc06d6f3f916a58ebb637c0ec5f2179b93d32b9983018c2f3
4
+ data.tar.gz: 482a18f5e8b462b23621d05e8790b1d6f650f2ac8ac3169f40915f2f88e8212a
5
5
  SHA512:
6
- metadata.gz: 76dfe545911af381aa149e5821d6da45563a4d7a6659438cc4dc1fd02a2148ebba1d814f1a7dc3cb53e5a458b363d9e299b56ac614e1bf17cacd076cd7b9fceb
7
- data.tar.gz: 1f774dbc9a4d2c47486a4f4bbc185b480bed3ef714792cac911eadd8806fa421f63e0c9375f311cd437797f41f03e5f996dfcf49b13e938b26ca8adb6e700c6c
6
+ metadata.gz: 91e3ded5751df8d330c86fb909c3124ddc386c2f4a1fadd9e3f0a0ecfd4f60276c3e98d67f09e4819e585bf65c401c0a6173ad406b3227d9ebec4726f00103fd
7
+ data.tar.gz: 36668d33ab9be1528af87c4433e51ca73ce9f137bce9dd58c511aaf0ec3b3e410556097c2df5d0f35d34db970809b3c625a413c931dd01cb845b34ecf2f963c9
@@ -1,3 +1,3 @@
1
1
  module Lutaml
2
- VERSION = "0.9.19".freeze
2
+ VERSION = "0.9.21".freeze
3
3
  end
@@ -3,7 +3,7 @@
3
3
  module Lutaml
4
4
  module XMI
5
5
  class GeneralizationAttributeDrop < Liquid::Drop
6
- def initialize(attr, upper_klass, gen_name, guidance = nil) # rubocop:disable Lint/MissingSuper
6
+ def initialize(attr, upper_klass, gen_name, guidance = nil) # rubocop:disable Lint/MissingSuper,Metrics/ParameterLists,Layout/LineLength
7
7
  @attr = attr
8
8
  @upper_klass = upper_klass
9
9
  @gen_name = gen_name
@@ -26,7 +26,7 @@ module Lutaml
26
26
  @attr[:xmi_id]
27
27
  end
28
28
 
29
- def is_derived
29
+ def is_derived # rubocop:disable Naming/PredicateName
30
30
  @attr[:is_derived]
31
31
  end
32
32
 
@@ -59,15 +59,7 @@ module Lutaml
59
59
  end
60
60
 
61
61
  def name_ns
62
- name_ns = case @attr[:type_ns]
63
- when "core", "gml"
64
- upper_klass
65
- else
66
- @attr[:type_ns]
67
- end
68
-
69
- name_ns = upper_klass if name_ns.nil?
70
- name_ns
62
+ @attr[:name_ns]
71
63
  end
72
64
 
73
65
  def used?
@@ -32,10 +32,19 @@ module Lutaml
32
32
  end
33
33
 
34
34
  def attributes
35
- @gen[:general_attributes]
36
- # @gen[:general_attributes].map do |attr|
37
- # GeneralizationAttributeDrop.new(attr, upper_klass, name)
38
- # end
35
+ attrs = @gen[:general_attributes]
36
+ attrs.each do |i|
37
+ name_ns = case i[:type_ns]
38
+ when "core", "gml"
39
+ upper_klass
40
+ else
41
+ i[:type_ns]
42
+ end
43
+ name_ns = upper_klass if name_ns.nil?
44
+
45
+ i[:name_ns] = name_ns
46
+ i[:name] = "" if i[:name].nil?
47
+ end
39
48
  end
40
49
 
41
50
  def type
@@ -51,53 +60,112 @@ module Lutaml
51
60
  end
52
61
 
53
62
  # get attributes without association
54
- def owned_props
55
- attributes.select do |attr|
56
- attr[:association].nil?
57
- end.map do |attr|
58
- GeneralizationAttributeDrop.new(attr, upper_klass, name, @guidance)
59
- end
63
+ def owned_props(sort: false)
64
+ return [] unless attributes
65
+
66
+ props = attributes.select { |attr| attr[:association].nil? }
67
+ props = sort_props(props) if sort
68
+ props_to_liquid(props)
60
69
  end
61
70
 
62
71
  # get attributes with association
63
- def assoc_props
64
- attributes.select do |attr|
65
- attr[:association]
66
- end.map do |attr|
72
+ def assoc_props(sort: false)
73
+ return [] unless attributes
74
+
75
+ props = attributes.select { |attr| attr[:association].nil? == false }
76
+ props = sort_props(props) if sort
77
+ props_to_liquid(props)
78
+ end
79
+
80
+ def props_to_liquid(props)
81
+ props.map do |attr|
67
82
  GeneralizationAttributeDrop.new(attr, upper_klass, name, @guidance)
68
83
  end
69
84
  end
70
85
 
71
86
  # get items without association by looping through the generation
72
- def inherited_props
87
+ def inherited_props(sort: false)
73
88
  loop_general_item unless @looped_general_item
74
89
 
75
- @inherited_props.reverse
90
+ props = @inherited_props.reverse
91
+ props = sort_props_with_level(props) if sort
92
+ props_hash_to_liquid(props)
76
93
  end
77
94
 
78
95
  # get items with association by looping through the generation
79
- def inherited_assoc_props
96
+ def inherited_assoc_props(sort: false)
80
97
  loop_general_item unless @looped_general_item
81
98
 
82
- @inherited_assoc_props.reverse
99
+ props = @inherited_assoc_props.reverse
100
+ props = sort_props_with_level(props) if sort
101
+ props_hash_to_liquid(props)
102
+ end
103
+
104
+ def sort_props_with_level(arr)
105
+ return [] if arr.nil? || arr.empty?
106
+
107
+ # level desc, name_ns asc, name asc
108
+ arr.sort_by { |i| [-i[:level], i[:attr][:name_ns], i[:attr][:name]] }
109
+ end
110
+
111
+ def props_hash_to_liquid(prop_hash_arr)
112
+ prop_hash_arr.map do |prop_hash|
113
+ GeneralizationAttributeDrop.new(
114
+ prop_hash[:attr],
115
+ prop_hash[:gen_upper_klass],
116
+ prop_hash[:gen_name],
117
+ prop_hash[:guidance],
118
+ )
119
+ end
120
+ end
121
+
122
+ def sorted_owned_props
123
+ owned_props(sort: true)
124
+ end
125
+
126
+ def sorted_assoc_props
127
+ assoc_props(sort: true)
83
128
  end
84
129
 
85
- def loop_general_item # rubocop:disable Metrics/MethodLength
130
+ def sorted_inherited_props
131
+ inherited_props(sort: true)
132
+ end
133
+
134
+ def sorted_inherited_assoc_props
135
+ inherited_assoc_props(sort: true)
136
+ end
137
+
138
+ def sort_props(arr)
139
+ return [] if arr.nil? || arr.empty?
140
+
141
+ arr.sort_by { |i| [i[:name_ns], i[:name]] }
142
+ end
143
+
144
+ def loop_general_item # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
86
145
  general_item = general
146
+ level = 0
147
+
87
148
  while general_item.has_general?
88
149
  gen_upper_klass = general_item.upper_klass
89
150
  gen_name = general_item.name
90
151
  # reverse the order to show super class first
91
152
  general_item.attributes.reverse_each do |attr|
92
- attr_drop = GeneralizationAttributeDrop.new(attr, gen_upper_klass,
93
- gen_name, @guidance)
153
+ attr_hash = {
154
+ attr: attr,
155
+ gen_upper_klass: gen_upper_klass,
156
+ gen_name: gen_name,
157
+ guidance: @guidance,
158
+ }
159
+ attr_hash[:level] = level
160
+
94
161
  if attr[:association]
95
- @inherited_assoc_props << attr_drop
162
+ @inherited_assoc_props << attr_hash
96
163
  else
97
- @inherited_props << attr_drop
164
+ @inherited_props << attr_hash
98
165
  end
99
166
  end
100
167
 
168
+ level += 1
101
169
  general_item = general_item.general
102
170
  end
103
171
 
@@ -63,6 +63,10 @@ module Lutaml
63
63
  @klass_guidance)
64
64
  end
65
65
 
66
+ def has_guidance?
67
+ !!@klass_guidance
68
+ end
69
+
66
70
  def is_abstract
67
71
  @model[:is_abstract]
68
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.19
4
+ version: 0.9.21
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-10-23 00:00:00.000000000 Z
11
+ date: 2024-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid