Class: Lutaml::Xmi::LiquidDrops::GeneralizationDrop
- Inherits:
-
Liquid::Drop
- Object
- Liquid::Drop
- Lutaml::Xmi::LiquidDrops::GeneralizationDrop
- Includes:
- Parsers::XmiBase
- Defined in:
- lib/lutaml/xmi/liquid_drops/generalization_drop.rb
Instance Method Summary collapse
-
#assoc_props(sort: false) ⇒ Object
get attributes with association.
-
#attributes ⇒ Object
rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity.
- #definition ⇒ Object
- #general ⇒ Object
- #has_general? ⇒ Boolean
- #id ⇒ Object
-
#inherited_assoc_props(sort: false) ⇒ Object
get items with association by looping through the generation.
-
#inherited_props(sort: false) ⇒ Object
get items without association by looping through the generation.
-
#initialize(gen, guidance = nil, options = {}) ⇒ GeneralizationDrop
constructor
rubocop:disable Lint/MissingSuper.
-
#loop_general_item ⇒ Object
rubocop:disable Metrics/MethodLength,Metrics/AbcSize.
- #name ⇒ Object
-
#owned_props(sort: false) ⇒ Object
get attributes without association.
- #props_hash_to_liquid(prop_hash_arr) ⇒ Object
- #props_to_liquid(props) ⇒ Object
- #sort_props(arr) ⇒ Object
- #sort_props_with_level(arr) ⇒ Object
- #sorted_assoc_props ⇒ Object
- #sorted_inherited_assoc_props ⇒ Object
- #sorted_inherited_props ⇒ Object
- #sorted_owned_props ⇒ Object
- #stereotype ⇒ Object
- #type ⇒ Object
- #upper_klass ⇒ Object
Methods included from Parsers::XmiBase
Constructor Details
#initialize(gen, guidance = nil, options = {}) ⇒ GeneralizationDrop
rubocop:disable Lint/MissingSuper
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 9 def initialize(gen, guidance = nil, = {}) # rubocop:disable Lint/MissingSuper @gen = gen @looped_general_item = false @inherited_props = [] @inherited_assoc_props = [] @guidance = guidance @options = @xmi_root_model = [:xmi_root_model] @id_name_mapping = [:id_name_mapping] end |
Instance Method Details
#assoc_props(sort: false) ⇒ Object
get attributes with association
80 81 82 83 84 85 86 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 80 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,Metrics/AbcSize,Metrics/CyclomaticComplexity
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 42 def attributes # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity attrs = @gen[:general_attributes] attrs.each do |i| name_ns = case i[:type_ns] when "core", "gml" upper_klass&.name else i[:type_ns] end name_ns = upper_klass&.name if name_ns.nil? i[:name_ns] = name_ns i[:name] = "" if i[:name].nil? end end |
#definition ⇒ Object
62 63 64 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 62 def definition @gen[:definition] end |
#general ⇒ Object
32 33 34 35 36 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 32 def general if @gen[:general] GeneralizationDrop.new(@gen[:general], @guidance, @options) end end |
#has_general? ⇒ Boolean
38 39 40 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 38 def has_general? !!@gen[:general] end |
#id ⇒ Object
20 21 22 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 20 def id @gen[:general_id] end |
#inherited_assoc_props(sort: false) ⇒ Object
get items with association by looping through the generation
104 105 106 107 108 109 110 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 104 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
95 96 97 98 99 100 101 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 95 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
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 181 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 152 def loop_general_item # rubocop:disable Metrics/MethodLength,Metrics/AbcSize general_item = general level = 0 while general_item.has_general? gen_upper_klass = general_item.upper_klass gen_name = general_item.name # reverse the order to show super class first 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
24 25 26 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 24 def name @gen[:general_name] end |
#owned_props(sort: false) ⇒ Object
get attributes without association
71 72 73 74 75 76 77 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 71 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
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 119 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
88 89 90 91 92 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 88 def props_to_liquid(props) props.map do |attr| GeneralizationAttributeDrop.new(attr, upper_klass, name, @guidance) end end |
#sort_props(arr) ⇒ Object
146 147 148 149 150 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 146 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
112 113 114 115 116 117 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 112 def sort_props_with_level(arr) return [] if arr.nil? || arr.empty? # level desc, name_ns asc, name asc arr.sort_by { |i| [-i[:level], i[:attr][:name_ns], i[:attr][:name]] } end |
#sorted_assoc_props ⇒ Object
134 135 136 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 134 def sorted_assoc_props assoc_props(sort: true) end |
#sorted_inherited_assoc_props ⇒ Object
142 143 144 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 142 def sorted_inherited_assoc_props inherited_assoc_props(sort: true) end |
#sorted_inherited_props ⇒ Object
138 139 140 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 138 def sorted_inherited_props inherited_props(sort: true) end |
#sorted_owned_props ⇒ Object
130 131 132 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 130 def sorted_owned_props owned_props(sort: true) end |
#stereotype ⇒ Object
66 67 68 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 66 def stereotype @gen[:stereotype] end |
#type ⇒ Object
58 59 60 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 58 def type @gen[:type] end |
#upper_klass ⇒ Object
28 29 30 |
# File 'lib/lutaml/xmi/liquid_drops/generalization_drop.rb', line 28 def upper_klass @gen[:general_upper_klass] end |