Class: Lutaml::UmlRepository::Presenters::DataTypePresenter
- Inherits:
-
ElementPresenter
- Object
- ElementPresenter
- Lutaml::UmlRepository::Presenters::DataTypePresenter
- Defined in:
- lib/lutaml/uml_repository/presenters/datatype_presenter.rb
Overview
Presenter for UML DataType elements.
Formats data type information including attributes and operations.
Instance Attribute Summary
Attributes inherited from ElementPresenter
#context, #element, #repository
Instance Method Summary collapse
-
#initialize(element, repository = nil, context = nil) ⇒ DataTypePresenter
constructor
A new instance of DataTypePresenter.
-
#to_hash ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
- #to_table_row ⇒ Object
-
#to_text ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
Constructor Details
#initialize(element, repository = nil, context = nil) ⇒ DataTypePresenter
Returns a new instance of DataTypePresenter.
13 14 15 |
# File 'lib/lutaml/uml_repository/presenters/datatype_presenter.rb', line 13 def initialize(element, repository = nil, context = nil) super end |
Instance Method Details
#to_hash ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/lutaml/uml_repository/presenters/datatype_presenter.rb', line 69 def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity data = { type: "DataType", name: element.name, } data[:xmi_id] = element.xmi_id if element.respond_to?(:xmi_id) && element.xmi_id data[:data_type] = element.type if element.respond_to?(:type) && element.type data[:stereotype] = element.stereotype if element.respond_to?(:stereotype) && element.stereotype data[:visibility] = element.visibility if element.respond_to?(:visibility) && element.visibility data[:is_abstract] = element.is_abstract if element.respond_to?(:is_abstract) if element.attributes && !element.attributes.empty? data[:attributes] = element.attributes.map do |attr| { name: attr.name, type: attr.type, } end end if element.respond_to?(:operations) && element.operations && !element.operations.empty? data[:operations] = element.operations.map(&:name) end data end |
#to_table_row ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/lutaml/uml_repository/presenters/datatype_presenter.rb', line 60 def to_table_row attr_count = element.attributes ? element.attributes.size : 0 { type: "DataType", name: element.name || "(unnamed)", details: "#{attr_count} attribute(s)", } end |
#to_text ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lutaml/uml_repository/presenters/datatype_presenter.rb', line 17 def to_text # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity lines = [] lines << "DataType: #{element.name}" lines << ("=" * 50) lines << "" lines << "Name: #{element.name}" if element.respond_to?(:xmi_id) && element.xmi_id lines << "XMI ID: #{element.xmi_id}" end if element.respond_to?(:type) && element.type lines << "Type: #{element.type}" end if element.respond_to?(:stereotype) && element.stereotype lines << "Stereotype: #{element.stereotype}" end if element.respond_to?(:visibility) && element.visibility lines << "Visibility: #{element.visibility}" end if element.respond_to?(:is_abstract) lines << "Abstract: #{element.is_abstract}" end lines << "" if element.attributes && !element.attributes.empty? lines << "Attributes (#{element.attributes.size}):" element.attributes.each do |attr| type_info = attr.type ? " : #{attr.type}" : "" lines << " - #{attr.name}#{type_info}" end lines << "" end if element.respond_to?(:operations) && element.operations && !element.operations.empty? lines << "Operations (#{element.operations.size}):" element.operations.each do |op| lines << " - #{op.name}()" end end lines.join("\n") end |