Class: Lutaml::Xmi::Parsers::Xml
- Inherits:
-
Object
- Object
- Lutaml::Xmi::Parsers::Xml
- Includes:
- Converter::XmiToUml, XmiBase
- Defined in:
- lib/lutaml/xmi/parsers/xml.rb
Overview
Class for parsing .xmi schema files into ::Lutaml::Uml::Document
Instance Attribute Summary collapse
-
#all_packaged_elements_cache ⇒ Object
readonly
Returns the value of attribute all_packaged_elements_cache.
-
#id_name_mapping ⇒ Object
readonly
Returns the value of attribute id_name_mapping.
-
#xmi_root_model ⇒ Object
readonly
Returns the value of attribute xmi_root_model.
Class Method Summary collapse
- .parse(xml, _options = {}) ⇒ Lutaml::Uml::Document
- .serialize_enumeration_by_name(xmi_path, name) ⇒ Hash
- .serialize_generalization_by_name(xmi_path, name, guidance = nil) ⇒ Hash
- .serialize_xmi(xml, with_gen: false) ⇒ Hash
- .serialize_xmi_to_liquid(xml, guidance = nil) ⇒ Liquid::Drop
Instance Method Summary collapse
- #parse(xmi_model) ⇒ Lutaml::Uml::Document
- #serialize_enumeration_by_name(xmi_model, name, id_name_mapping = nil) ⇒ Hash
- #serialize_generalization_by_name(xmi_model, name, guidance = nil, id_name_mapping = nil) ⇒ Hash
-
#serialize_xmi(xmi_model, with_gen: false, with_absolute_path: false) ⇒ Object
return [Hash].
-
#serialize_xmi_to_liquid(xmi_model, guidance = nil) ⇒ Object
return [Liquid::Drop].
Methods included from XmiBase
included, #set_xmi_model, #xmi_index
Methods included from Converter::XmiToUml
#create_uml_assoc_generalizations, #create_uml_associations, #create_uml_attribute, #create_uml_attributes, #create_uml_cardinality, #create_uml_class, #create_uml_class_attributes, #create_uml_classes, #create_uml_constraints, #create_uml_data_types, #create_uml_diagrams, #create_uml_document, #create_uml_enums, #create_uml_generalization, #create_uml_operations, #create_uml_package, #create_uml_packages, #create_uml_values, #find_owner_attribute_name, #get_uml_general, #get_uml_general_attributes, #loop_general_item, #set_uml_generalization
Instance Attribute Details
#all_packaged_elements_cache ⇒ Object (readonly)
Returns the value of attribute all_packaged_elements_cache.
19 20 21 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 19 def all_packaged_elements_cache @all_packaged_elements_cache end |
#id_name_mapping ⇒ Object (readonly)
Returns the value of attribute id_name_mapping.
19 20 21 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 19 def id_name_mapping @id_name_mapping end |
#xmi_root_model ⇒ Object (readonly)
Returns the value of attribute xmi_root_model.
19 20 21 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 19 def xmi_root_model @xmi_root_model end |
Class Method Details
.parse(xml, _options = {}) ⇒ Lutaml::Uml::Document
28 29 30 31 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 28 def parse(xml, = {}) xmi_model = get_xmi_model(xml) new.parse(xmi_model) end |
.serialize_enumeration_by_name(xmi_path, name) ⇒ Hash
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 76 def serialize_enumeration_by_name( # rubocop:disable Metrics/MethodLength xmi_path, name ) # Load from cache or file xml_cache_key = (Digest::SHA256.file xmi_path).hexdigest xmi_model = @xmi_root_model_cache_static[xml_cache_key] || get_xmi_model(xmi_path) id_name_mapping = @id_name_mapping_static[xml_cache_key] instance = new enum = instance.serialize_enumeration_by_name( xmi_model, name, id_name_mapping ) # Put xmi_model and id_name_mapping to cache @id_name_mapping_static[xml_cache_key] ||= instance.id_name_mapping @xmi_root_model_cache_static[xml_cache_key] ||= xmi_model enum end |
.serialize_generalization_by_name(xmi_path, name, guidance = nil) ⇒ Hash
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 52 def serialize_generalization_by_name( # rubocop:disable Metrics/MethodLength xmi_path, name, guidance = nil ) # Load from cache or file xml_cache_key = (Digest::SHA256.file xmi_path).hexdigest xmi_model = @xmi_root_model_cache_static[xml_cache_key] || get_xmi_model(xmi_path) id_name_mapping = @id_name_mapping_static[xml_cache_key] instance = new ret_val = instance.serialize_generalization_by_name( xmi_model, name, guidance, id_name_mapping ) # Put xmi_model and id_name_mapping to cache @id_name_mapping_static[xml_cache_key] ||= instance.id_name_mapping @xmi_root_model_cache_static[xml_cache_key] ||= xmi_model ret_val end |
.serialize_xmi(xml, with_gen: false) ⇒ Hash
36 37 38 39 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 36 def serialize_xmi(xml, with_gen: false) xmi_model = get_xmi_model(xml) new.serialize_xmi(xmi_model, with_gen: with_gen) end |
.serialize_xmi_to_liquid(xml, guidance = nil) ⇒ Liquid::Drop
43 44 45 46 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 43 def serialize_xmi_to_liquid(xml, guidance = nil) xmi_model = get_xmi_model(xml) new.serialize_xmi_to_liquid(xmi_model, guidance) end |
Instance Method Details
#parse(xmi_model) ⇒ Lutaml::Uml::Document
100 101 102 103 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 100 def parse(xmi_model) set_xmi_model(xmi_model) create_uml_document(xmi_model) end |
#serialize_enumeration_by_name(xmi_model, name, id_name_mapping = nil) ⇒ Hash
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 161 def serialize_enumeration_by_name( # rubocop:disable Metrics/MethodLength xmi_model, name, id_name_mapping = nil ) set_xmi_model(xmi_model, id_name_mapping) enum = find_enum_packaged_element_by_name(name) = { xmi_root_model: @xmi_root_model, id_name_mapping: @id_name_mapping, with_gen: true, with_absolute_path: true, } puts "Error: Enumeration not found for name: #{name}!" if enum.nil? ::Lutaml::Xmi::LiquidDrops::EnumDrop.new(enum, ) end |
#serialize_generalization_by_name(xmi_model, name, guidance = nil, id_name_mapping = nil) ⇒ Hash
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 138 def serialize_generalization_by_name( # rubocop:disable Metrics/MethodLength xmi_model, name, guidance = nil, id_name_mapping = nil ) set_xmi_model(xmi_model, id_name_mapping) klass = find_klass_packaged_element(name) = { xmi_root_model: @xmi_root_model, id_name_mapping: @id_name_mapping, with_gen: true, with_absolute_path: true, } puts "Error: Class not found for name: #{name}!" if klass.nil? ::Lutaml::Xmi::LiquidDrops::KlassDrop.new( klass, guidance, , ) end |
#serialize_xmi(xmi_model, with_gen: false, with_absolute_path: false) ⇒ Object
return [Hash]
109 110 111 112 113 114 115 116 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 109 def serialize_xmi(xmi_model, with_gen: false, with_absolute_path: false) set_xmi_model(xmi_model) serialize_to_hash( xmi_model, with_gen: with_gen, with_absolute_path: with_absolute_path, ) end |
#serialize_xmi_to_liquid(xmi_model, guidance = nil) ⇒ Object
return [Liquid::Drop]
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/lutaml/xmi/parsers/xml.rb', line 121 def serialize_xmi_to_liquid(xmi_model, guidance = nil) set_xmi_model(xmi_model) model = xmi_model.model = { xmi_root_model: @xmi_root_model, id_name_mapping: @id_name_mapping, with_gen: true, with_absolute_path: true, } ::Lutaml::Xmi::LiquidDrops::RootDrop.new(model, guidance, ) end |