Class: Lutaml::XMI::GeneralizationDrop
- Inherits:
-
Liquid::Drop
- Object
- Liquid::Drop
- Lutaml::XMI::GeneralizationDrop
show all
- Includes:
- Parsers::XMIBase
- Defined in:
- lib/lutaml/xmi/liquid_drops/generalization_drop.rb
Instance Method Summary
collapse
#get_guidance, included, #set_xmi_model
Constructor Details
#initialize(gen, guidance = nil, options = {}) ⇒ GeneralizationDrop
rubocop:disable Lint/MissingSuper
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 8
def initialize(gen, guidance = nil, options = {}) @gen = gen
@looped_general_item = false
@inherited_props = []
@inherited_assoc_props = []
@guidance = guidance
@options = options
@xmi_root_model = options[:xmi_root_model]
@xmi_cache = options[:xmi_cache]
end
|
Instance Method Details
#assoc_props(sort: false) ⇒ Object
get attributes with association
79
80
81
82
83
84
85
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 79
def assoc_props(sort: false)
return [] unless attributes
props = attributes.select { |attr| attr[:association].nil? == false }
props = sort_props(props) if sort
props_to_liquid(props)
end
|
#attributes ⇒ Object
rubocop:disable Metrics/MethodLength
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 41
def attributes attrs = @gen[:general_attributes]
attrs.each do |i|
name_ns = case i[:type_ns]
when "core", "gml"
upper_klass
else
i[:type_ns]
end
name_ns = upper_klass if name_ns.nil?
i[:name_ns] = name_ns
i[:name] = "" if i[:name].nil?
end
end
|
#definition ⇒ Object
61
62
63
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 61
def definition
@gen[:definition]
end
|
#general ⇒ Object
31
32
33
34
35
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 31
def general
if @gen[:general]
GeneralizationDrop.new(@gen[:general], @guidance, @options)
end
end
|
#has_general? ⇒ Boolean
37
38
39
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 37
def has_general?
!!@gen[:general]
end
|
#id ⇒ Object
19
20
21
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 19
def id
@gen[:general_id]
end
|
#inherited_assoc_props(sort: false) ⇒ Object
get items with association by looping through the generation
103
104
105
106
107
108
109
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 103
def inherited_assoc_props(sort: false)
loop_general_item unless @looped_general_item
props = @inherited_assoc_props.reverse
props = sort_props_with_level(props) if sort
props_hash_to_liquid(props)
end
|
#inherited_props(sort: false) ⇒ Object
get items without association by looping through the generation
94
95
96
97
98
99
100
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 94
def inherited_props(sort: false)
loop_general_item unless @looped_general_item
props = @inherited_props.reverse
props = sort_props_with_level(props) if sort
props_hash_to_liquid(props)
end
|
#loop_general_item ⇒ Object
rubocop:disable Metrics/MethodLength,Metrics/AbcSize
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 151
def loop_general_item general_item = general
level = 0
while general_item.has_general?
gen_upper_klass = general_item.upper_klass
gen_name = general_item.name
general_item.attributes.reverse_each do |attr|
attr_hash = {
attr: attr,
gen_upper_klass: gen_upper_klass,
gen_name: gen_name,
guidance: @guidance,
}
attr_hash[:level] = level
if attr[:association]
@inherited_assoc_props << attr_hash
else
@inherited_props << attr_hash
end
end
level += 1
general_item = general_item.general
end
@looped_general_item = true
end
|
#name ⇒ Object
23
24
25
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 23
def name
@gen[:general_name]
end
|
#owned_props(sort: false) ⇒ Object
get attributes without association
70
71
72
73
74
75
76
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 70
def owned_props(sort: false)
return [] unless attributes
props = attributes.select { |attr| attr[:association].nil? }
props = sort_props(props) if sort
props_to_liquid(props)
end
|
#props_hash_to_liquid(prop_hash_arr) ⇒ Object
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 118
def props_hash_to_liquid(prop_hash_arr)
prop_hash_arr.map do |prop_hash|
GeneralizationAttributeDrop.new(
prop_hash[:attr],
prop_hash[:gen_upper_klass],
prop_hash[:gen_name],
prop_hash[:guidance],
)
end
end
|
#props_to_liquid(props) ⇒ Object
87
88
89
90
91
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 87
def props_to_liquid(props)
props.map do |attr|
GeneralizationAttributeDrop.new(attr, upper_klass, name, @guidance)
end
end
|
#sort_props(arr) ⇒ Object
145
146
147
148
149
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 145
def sort_props(arr)
return [] if arr.nil? || arr.empty?
arr.sort_by { |i| [i[:name_ns], i[:name]] }
end
|
#sort_props_with_level(arr) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 111
def sort_props_with_level(arr)
return [] if arr.nil? || arr.empty?
arr.sort_by { |i| [-i[:level], i[:attr][:name_ns], i[:attr][:name]] }
end
|
#sorted_assoc_props ⇒ Object
133
134
135
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 133
def sorted_assoc_props
assoc_props(sort: true)
end
|
#sorted_inherited_assoc_props ⇒ Object
141
142
143
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 141
def sorted_inherited_assoc_props
inherited_assoc_props(sort: true)
end
|
#sorted_inherited_props ⇒ Object
137
138
139
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 137
def sorted_inherited_props
inherited_props(sort: true)
end
|
#sorted_owned_props ⇒ Object
129
130
131
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 129
def sorted_owned_props
owned_props(sort: true)
end
|
#stereotype ⇒ Object
65
66
67
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 65
def stereotype
@gen[:stereotype]
end
|
#type ⇒ Object
57
58
59
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 57
def type
@gen[:type]
end
|
#upper_klass ⇒ Object
27
28
29
|
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 27
def upper_klass
@gen[:general_upper_klass]
end
|