lutaml 0.9.18 → 0.9.20

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: a78a8cd7a54dcb75279728cff484e7a8bfcbc3258f8a8ee155a2368ce21ade87
4
- data.tar.gz: 823a52c70df804f61e430d143471daf3580f271331e02306501f06925ed55346
3
+ metadata.gz: 73252a1880283e31b2954654b4e046f1eda11e43eb3bd4eaf75e5e066ddaf539
4
+ data.tar.gz: 0e189f762028fe432169d63a19755f1fea34ca22575beb454bbdcbe46219bf4e
5
5
  SHA512:
6
- metadata.gz: 0466df4efa98e478bbfdb1e5739425bd02b59e20d8c780d3caea203ce87e99183a5c8f003c6418a76be7dc0abb0346a57403b7b7fde9b6d11f2810186f24ce4f
7
- data.tar.gz: 2c342890469f5022c5d3040e9ca7f2c7dbe302f339356458fb62558c6da382c7281133acc344a1de9649815bca5ea0175265aae1eaf7373c44c87ed3f51acd57
6
+ metadata.gz: 99014430718d84a8e56361b06962ddeb75ba369e05d54d53a1b55d181ba681c4a3d04c5a31c40e1142ca4621e91a063e3ac7767d6feb859d276f6cd23406cb56
7
+ data.tar.gz: e484203747c7501e8ec17ae454e72ffeba6fdf72d29edf673ddb6274ae9925435fe8e6389014b463635f45debecba9ca4c5cb96e4865a211589bb3b3a4a37679
@@ -1,3 +1,3 @@
1
1
  module Lutaml
2
- VERSION = "0.9.18".freeze
2
+ VERSION = "0.9.20".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
 
@@ -262,8 +262,7 @@ module Lutaml
262
262
  # @param general_node [Shale::Mapper]
263
263
  # @return [Hash]
264
264
  def get_general_attributes(general_node)
265
- attrs = serialize_class_attributes(general_node, with_assoc: true)
266
- attrs.sort_by { |i| i[:name].to_s }
265
+ serialize_class_attributes(general_node, with_assoc: true)
267
266
  end
268
267
 
269
268
  # @param general_node [Shale::Mapper]
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.18
4
+ version: 0.9.20
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-22 00:00:00.000000000 Z
11
+ date: 2024-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid