Module: Lutaml::Converter::DslToUml

Included in:
Uml::Parsers::Dsl
Defined in:
lib/lutaml/converter/dsl_to_uml.rb

Instance Method Summary collapse

Instance Method Details

#create_uml_association(hash) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 55

def create_uml_association(hash) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  ::Lutaml::Uml::Association.new.tap do |model|
    member_end_cardinality = hash.delete(:member_end_cardinality)
    if member_end_cardinality
      model.member_end_cardinality = create_uml_cardinality(
        member_end_cardinality,
      )
    end
    owner_end_cardinality = hash.delete(:owner_end_cardinality)
    if owner_end_cardinality
      model.owner_end_cardinality = create_uml_cardinality(
        owner_end_cardinality,
      )
    end

    set_uml_model(model, hash)
  end
end

#create_uml_associations(model, hash) ⇒ Object



196
197
198
199
200
201
202
203
204
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 196

def create_uml_associations(model, hash)
  associations = hash.delete(:associations)
  return [] if associations.nil?

  attr = create_uml_association(associations)
  model.associations = [] if model.associations.nil?
  model.associations << attr
  hash
end

#create_uml_attribute(hash) ⇒ Object

rubocop:disable Metrics/AbcSize



42
43
44
45
46
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 42

def create_uml_attribute(hash) # rubocop:disable Metrics/AbcSize
  ::Lutaml::Uml::TopElementAttribute.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_attributes(model, hash) ⇒ Object



186
187
188
189
190
191
192
193
194
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 186

def create_uml_attributes(model, hash)
  attributes = hash.delete(:attributes)
  return [] if attributes.nil?

  attr = create_uml_attribute(attributes)
  model.attributes = [] if model.attributes.nil?
  model.attributes << attr
  hash
end

#create_uml_cardinality(hash) ⇒ Object



48
49
50
51
52
53
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 48

def create_uml_cardinality(hash)
  ::Lutaml::Uml::Cardinality.new.tap do |cardinality|
    cardinality.min = hash[:min]
    cardinality.max = hash[:max]
  end
end

#create_uml_class(hash) ⇒ Object



18
19
20
21
22
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 18

def create_uml_class(hash)
  ::Lutaml::Uml::Class.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_classes(model, hash) ⇒ Object



146
147
148
149
150
151
152
153
154
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 146

def create_uml_classes(model, hash)
  classes = hash.delete(:classes)
  return [] if classes.nil?

  attr = create_uml_class(classes)
  model.classes = [] if model.classes.nil?
  model.classes << attr
  hash
end

#create_uml_constraint(hash) ⇒ Object



80
81
82
83
84
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 80

def create_uml_constraint(hash)
  ::Lutaml::Uml::Constraint.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_constraints(model, hash) ⇒ Object



216
217
218
219
220
221
222
223
224
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 216

def create_uml_constraints(model, hash)
  constraints = hash.delete(:constraints)
  return [] if constraints.nil?

  attr = create_uml_constraint(constraints)
  model.constraints = [] if model.constraints.nil?
  model.constraints << attr
  hash
end

#create_uml_data_type(hash) ⇒ Object



30
31
32
33
34
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 30

def create_uml_data_type(hash)
  ::Lutaml::Uml::DataType.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_data_types(model, hash) ⇒ Object



166
167
168
169
170
171
172
173
174
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 166

def create_uml_data_types(model, hash)
  data_types = hash.delete(:data_types)
  return [] if data_types.nil?

  attr = create_uml_data_type(data_types)
  model.data_types = [] if model.data_types.nil?
  model.data_types << attr
  hash
end

#create_uml_diagram(hash) ⇒ Object



36
37
38
39
40
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 36

def create_uml_diagram(hash)
  ::Lutaml::Uml::Diagram.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_diagrams(model, hash) ⇒ Object



176
177
178
179
180
181
182
183
184
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 176

def create_uml_diagrams(model, hash)
  diagrams = hash.delete(:diagrams)
  return [] if diagrams.nil?

  attr = create_uml_diagram(diagrams)
  model.diagrams = [] if model.diagrams.nil?
  model.diagrams << attr
  hash
end

#create_uml_document(hash) ⇒ Object



6
7
8
9
10
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 6

def create_uml_document(hash)
  ::Lutaml::Uml::Document.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_enum(hash) ⇒ Object



24
25
26
27
28
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 24

def create_uml_enum(hash)
  ::Lutaml::Uml::Enum.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_enums(model, hash) ⇒ Object



156
157
158
159
160
161
162
163
164
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 156

def create_uml_enums(model, hash)
  enums = hash.delete(:enums)
  return [] if enums.nil?

  attr = create_uml_enum(enums)
  model.enums = [] if model.enums.nil?
  model.enums << attr
  hash
end

#create_uml_members(model, hash) ⇒ Object

rubocop:disable Metrics/MethodLength,Metrics/AbcSize



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 116

def create_uml_members(model, hash) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
  members = hash.delete(:members)
  members.to_a.each do |member_hash|
    member_hash.each do
      create_uml_packages(model, member_hash)
      create_uml_classes(model, member_hash)
      create_uml_enums(model, member_hash)
      create_uml_data_types(model, member_hash)
      create_uml_diagrams(model, member_hash)
      create_uml_attributes(model, member_hash)
      create_uml_associations(model, member_hash)
      create_uml_operations(model, member_hash)
      create_uml_constraints(model, member_hash)
      create_uml_values(model, member_hash)
      set_model_attribute(model, member_hash)
    end
  end
  hash
end

#create_uml_operation(hash) ⇒ Object



74
75
76
77
78
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 74

def create_uml_operation(hash)
  ::Lutaml::Uml::Operation.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_operations(model, hash) ⇒ Object



206
207
208
209
210
211
212
213
214
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 206

def create_uml_operations(model, hash)
  operations = hash.delete(:operations)
  return [] if operations.nil?

  attr = create_uml_operation(operations)
  model.operations = [] if model.operations.nil?
  model.operations << attr
  hash
end

#create_uml_package(hash) ⇒ Object



12
13
14
15
16
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 12

def create_uml_package(hash)
  ::Lutaml::Uml::Package.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_packages(model, hash) ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 136

def create_uml_packages(model, hash)
  packages = hash.delete(:packages)
  return [] if packages.nil?

  attr = create_uml_package(packages)
  model.packages = [] if model.packages.nil?
  model.packages << attr
  hash
end

#create_uml_value(hash) ⇒ Object



86
87
88
89
90
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 86

def create_uml_value(hash)
  ::Lutaml::Uml::Value.new.tap do |model|
    set_uml_model(model, hash)
  end
end

#create_uml_values(model, hash) ⇒ Object



226
227
228
229
230
231
232
233
234
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 226

def create_uml_values(model, hash)
  values = hash.delete(:values)
  return [] if values.nil?

  attr = create_uml_value(values)
  model.values = [] if model.values.nil?
  model.values << attr
  hash
end

#set_model_attribute(model, hash) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 97

def set_model_attribute(model, hash) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  hash.each do |key, value|
    if key == :definition
      value = value.to_s.gsub(/\\}/, "}").gsub(/\\{/, "{")
        .split("\n").map(&:strip).join("\n")
    end

    if model.respond_to?("#{key}=")
      if model.class.attributes[key.to_sym].options[:collection]
        values = model.send(key.to_sym).to_a
        values << value
        model.send("#{key}=", values)
      else
        model.send("#{key}=", value)
      end
    end
  end
end

#set_uml_model(model, hash) ⇒ Object



92
93
94
95
# File 'lib/lutaml/converter/dsl_to_uml.rb', line 92

def set_uml_model(model, hash)
  hash = create_uml_members(model, hash)
  set_model_attribute(model, hash)
end