Class: Lutaml::UmlRepository::Presenters::ClassPresenter

Inherits:
ElementPresenter show all
Defined in:
lib/lutaml/uml_repository/presenters/class_presenter.rb

Overview

Presenter for UML Class elements.

Formats class information for different output types: text, table rows, and structured data.

Instance Attribute Summary

Attributes inherited from ElementPresenter

#context, #element, #repository

Instance Method Summary collapse

Methods inherited from ElementPresenter

#initialize

Constructor Details

This class inherits a constructor from Lutaml::UmlRepository::Presenters::ElementPresenter

Instance Method Details

#to_hashHash

Generate structured hash.

Returns:

  • (Hash)

    Structured representation



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lutaml/uml_repository/presenters/class_presenter.rb', line 45

def to_hash # rubocop:disable Metrics/AbcSize
  data = {
    type: "Class",
    name: element.name,
    is_abstract: !!element.is_abstract,
  }

  data[:xmi_id] = element.xmi_id if element.xmi_id
  if element.stereotype
    data[:stereotype] = element.stereotype
  end

  data
end

#to_table_rowHash

Generate table row data.

Returns:

  • (Hash)

    Row data with :type, :name, :details keys



34
35
36
37
38
39
40
# File 'lib/lutaml/uml_repository/presenters/class_presenter.rb', line 34

def to_table_row
  {
    type: "Class",
    name: element.name || "(unnamed)",
    details: stereotype_display,
  }
end

#to_textString

Generate detailed text view.

Returns:

  • (String)

    Multi-line formatted text



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lutaml/uml_repository/presenters/class_presenter.rb', line 17

def to_text # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  lines = []
  lines << "Class: #{element.name}"
  lines << ("=" * 50)
  lines << ""
  lines << "Name:        #{element.name}"
  lines << "XMI ID:      #{element.xmi_id}" if
    element.xmi_id
  lines << "Stereotype:  #{element.stereotype}" if
    element.stereotype
  lines << "Abstract:    #{element.is_abstract}"
  lines.join("\n")
end