Class: Ea::Transformers::UmlToXmi::Writer
- Inherits:
-
Object
- Object
- Ea::Transformers::UmlToXmi::Writer
- Defined in:
- lib/ea/transformers/uml_to_xmi/writer.rb
Overview
Low-level XML structural primitives for emitting Sparx-flavored XMI.
This class has no UML domain knowledge — it only knows the XML shapes (XMI root, uml:Model, packagedElement, ownedAttribute, …) required to produce a well-formed Sparx XMI document. Transformer drives it.
Constant Summary collapse
- XMI_NS =
"http://www.omg.org/spec/XMI/20131001"- UML_NS =
"http://www.omg.org/spec/UML/20161101"
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
Instance Method Summary collapse
- #documentation(exporter: "ea-rb", exporter_version: Ea::VERSION) ⇒ Object
- #generalization(id, general_id) ⇒ Object
-
#initialize ⇒ Writer
constructor
A new instance of Writer.
- #owned_attribute(id, name, type: nil, visibility: "public") ⇒ Object
- #owned_literal(id, name) ⇒ Object
- #owned_operation(id, name, visibility: "public") ⇒ Object
- #packaged_element(uml_type, id, name, **attrs) ⇒ Object
- #to_xml ⇒ Object
- #uml_model(id, name) ⇒ Object
- #xmi_root ⇒ Object
Constructor Details
#initialize ⇒ Writer
Returns a new instance of Writer.
19 20 21 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 19 def initialize @builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
17 18 19 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 17 def builder @builder end |
Instance Method Details
#documentation(exporter: "ea-rb", exporter_version: Ea::VERSION) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 27 def documentation(exporter: "ea-rb", exporter_version: Ea::VERSION) @builder["xmi"].Documentation( exporter: exporter, exporterVersion: exporter_version, ) end |
#generalization(id, general_id) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 68 def generalization(id, general_id) @builder.generalization( "xmi:type": "uml:Generalization", "xmi:id": id, general: general_id, ) end |
#owned_attribute(id, name, type: nil, visibility: "public") ⇒ Object
48 49 50 51 52 53 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 48 def owned_attribute(id, name, type: nil, visibility: "public") attrs = { "xmi:type": "uml:Property", "xmi:id": id, name: name, visibility: visibility } attrs[:type] = type if type @builder.ownedAttribute(attrs) { yield self if block_given? } end |
#owned_literal(id, name) ⇒ Object
62 63 64 65 66 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 62 def owned_literal(id, name) @builder.ownedLiteral( "xmi:type": "uml:EnumerationLiteral", "xmi:id": id, name: name, ) end |
#owned_operation(id, name, visibility: "public") ⇒ Object
55 56 57 58 59 60 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 55 def owned_operation(id, name, visibility: "public") @builder.ownedOperation( "xmi:type": "uml:Operation", "xmi:id": id, name: name, visibility: visibility, ) { yield self if block_given? } end |
#packaged_element(uml_type, id, name, **attrs) ⇒ Object
42 43 44 45 46 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 42 def packaged_element(uml_type, id, name, **attrs) @builder.packagedElement(packaged_attrs(uml_type, id, name, attrs)) do yield self if block_given? end end |
#to_xml ⇒ Object
76 77 78 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 76 def to_xml @builder.doc.to_xml end |
#uml_model(id, name) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 34 def uml_model(id, name) @builder["uml"].Model( "xmi:type": "uml:Model", "xmi:id": id, name: name, ) { yield self } end |
#xmi_root ⇒ Object
23 24 25 |
# File 'lib/ea/transformers/uml_to_xmi/writer.rb', line 23 def xmi_root @builder["xmi"].XMI(root_attributes) { yield self } end |