Module: Xumlidot::Diagram::Xmi::Klass

Includes:
Shared::Naming, ID
Defined in:
lib/xumlidot/diagram/xmi/klass.rb

Overview

Draw the klass

Defined Under Namespace

Modules: Name

Instance Method Summary collapse

Methods included from Shared::Naming

#draw_ancestor, #draw_identifier, #draw_name

Methods included from ID

#association_end_id, #association_id, #force_id, #gen_id, #id

Instance Method Details

#draw_diagramObject

Draws a diagram element i.e. the part which is rendered



43
44
45
46
47
48
49
50
51
# File 'lib/xumlidot/diagram/xmi/klass.rb', line 43

def draw_diagram
  xml = %(<uml:DiagramElement preferredShapeType="Class" subject="#{id}" xmi:id="#{id}de">
    </uml:DiagramElement>)

  return xml if @definition.superklass.empty? && @definition.inherited_modules.empty?
  return xml unless ::Xumlidot::Options.inheritance

  xml + draw_diagram_generalisation
end

#draw_diagram_composition(composee) ⇒ Object



111
112
113
114
# File 'lib/xumlidot/diagram/xmi/klass.rb', line 111

def draw_diagram_composition(composee)
  %(<uml:DiagramElement fromDiagramElement="#{id}de" preferredShapeType="Association" subject="#{association_id}" toDiagramElement="#{composee.id}de">
  </uml:DiagramElement>)
end

#draw_diagram_generalisationObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/xumlidot/diagram/xmi/klass.rb', line 53

def draw_diagram_generalisation
  xml = ''

  unless @definition.superklass.empty?
    xml += %(<uml:DiagramElement fromDiagramElement="#{@definition.superklass.id}de" preferredShapeType="Generalization" subject="#{gen_id}" toDiagramElement="#{id}de">
             </uml:DiagramElement>)
  end

  return xml if @definition.inherited_modules.empty?

  @definition.inherited_modules.each do |m|
    next if m.empty?

    xml += %(<uml:DiagramElement fromDiagramElement="#{m.id}de" preferredShapeType="Generalization" subject="#{gen_id}" toDiagramElement="#{id}de">
             </uml:DiagramElement>)
  end

  xml
end

#draw_klassObject

TODO: Split this into model and diagram classes class Model end class Diagram end



32
33
34
35
36
37
38
39
40
# File 'lib/xumlidot/diagram/xmi/klass.rb', line 32

def draw_klass # rubocop:disable Metrics/AbcSize
  definition.name.extend(Name)
  xmi = "<ownedMember isAbstract=\"false\" isActive=\"false\" isLeaf=\"false\" name=\"#{definition.name.to_xmi}\" visibility=\"public\" xmi:id=\"#{id}\" xmi:type=\"uml:Class\">"
  xmi += draw_model_inheritance if ::Xumlidot::Options.inheritance
  xmi += extend_and_draw(attributes)
  xmi += extend_and_draw(class_methods)
  xmi += extend_and_draw(instance_methods)
  "#{xmi}</ownedMember>"
end

#draw_model_composition(composee) ⇒ Object



100
101
102
103
104
105
106
107
108
109
# File 'lib/xumlidot/diagram/xmi/klass.rb', line 100

def draw_model_composition(composee)
  %(<ownedMember isAbstract="false" isDerived="false" isLeaf="false" xmi:id="#{association_id}" xmi:type="uml:Association">
      <memberEnd xmi:idref="#{association_end_id}"/>
      <ownedEnd aggregation="none" association="#{association_id}" isDerived="false" isDerivedUnion="false" isLeaf="false" isNavigable="true" isReadOnly="false" isStatic="false" type="#{id}" xmi:id="#{association_end_id}" xmi:type="uml:Property">
      </ownedEnd>
      <memberEnd xmi:idref="#{composee.association_end_id}"/>
      <ownedEnd aggregation="composite" association="#{association_id}" isDerived="false" isDerivedUnion="false" isLeaf="false" isNavigable="true" isReadOnly="false" isStatic="false" type="#{composee.id}" xmi:id="#{composee.association_end_id}" xmi:type="uml:Property">
      </ownedEnd>
    </ownedMember>)
end

#draw_model_inheritanceObject

Inheritance has to be drawn both as part of the model and as a part of the diagram

general = id = IMPORTANT; will be used to draw the lines in the diagram



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/xumlidot/diagram/xmi/klass.rb', line 79

def draw_model_inheritance # rubocop:disable Metrics/AbcSize
  return '' if @definition.superklass.empty? && @definition.inherited_modules.empty?

  xml = ''

  unless @definition.superklass.empty?
    xml += %(<generalization general="#{@definition.superklass.id}" xmi:id="#{gen_id}" xmi:type="uml:Generalization">
      </generalization>)
  end

  return xml if @definition.inherited_modules.empty?

  @definition.inherited_modules.each do |m|
    next if m.empty?

    xml += %(<generalization general="#{m.id}" xmi:id="#{gen_id}" xmi:type="uml:Generalization">
      </generalization>)
  end
  xml
end

#extend_and_draw(collection) ⇒ Object

Im not happy with this - xmi should not have to know about types and it should be a method



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/xumlidot/diagram/xmi/klass.rb', line 118

def extend_and_draw(collection)
  collection.map do |member|
    case member
    when ::Xumlidot::Types::MethodSignature
      member.extend(::Xumlidot::Diagram::Xmi::MethodSignature)
    when ::Xumlidot::Types::Attribute
      member.extend(::Xumlidot::Diagram::Xmi::Attribute)
    end
    member.draw
  end.join(' ')
end