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
66 67 68 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 |
# File 'lib/lutaml/uml_repository/presenters/datatype_presenter.rb', line 66 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.xmi_id data[:data_type] = element.type if element.type data[:stereotype] = element.stereotype if element.stereotype && !element.stereotype.empty? data[:visibility] = element.visibility if element.visibility data[:is_abstract] = element.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.operations && !element.operations.empty? data[:operations] = element.operations.map(&:name) end data end |
#to_table_row ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/lutaml/uml_repository/presenters/datatype_presenter.rb', line 57 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 |
# 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.xmi_id lines << "XMI ID: #{element.xmi_id}" end if element.type lines << "Type: #{element.type}" end if element.stereotype && !element.stereotype.empty? lines << "Stereotype: #{element.stereotype}" end if element.visibility lines << "Visibility: #{element.visibility}" end lines << "Abstract: #{element.is_abstract}" 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.operations && !element.operations.empty? lines << "Operations (#{element.operations.size}):" element.operations.each do |op| lines << " - #{op.name}()" end end lines.join("\n") end |