Class: Lutaml::Qea::Models::EaDiagramObject

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/lutaml/qea/models/ea_diagram_object.rb

Overview

Represents a diagram object from the t_diagramobjects table

This model represents the placement of UML elements (classes, packages, etc.) on specific diagrams, including their position and styling.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#primary_key

Class Method Details

.from_db_row(row) ⇒ EaDiagramObject?

Create from database row

Parameters:

  • row (Hash)

    Database row with string keys

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lutaml/qea/models/ea_diagram_object.rb', line 33

def self.from_db_row(row) # rubocop:disable Metrics/MethodLength
  return nil if row.nil?

  new(
    diagram_id: row["Diagram_ID"],
    ea_object_id: row["Object_ID"],
    recttop: row["RectTop"],
    rectleft: row["RectLeft"],
    rectright: row["RectRight"],
    rectbottom: row["RectBottom"],
    sequence: row["Sequence"],
    objectstyle: row["ObjectStyle"],
    instance_id: row["Instance_ID"],
  )
end

.primary_key_columnObject



21
22
23
# File 'lib/lutaml/qea/models/ea_diagram_object.rb', line 21

def self.primary_key_column
  :instance_id
end

.table_nameObject



25
26
27
# File 'lib/lutaml/qea/models/ea_diagram_object.rb', line 25

def self.table_name
  "t_diagramobjects"
end

Instance Method Details

#bounding_boxHash

Get the bounding box of the diagram object

Returns:

  • (Hash)

    Hash with :top, :left, :right, :bottom, :width, :height



51
52
53
54
55
56
57
58
59
60
# File 'lib/lutaml/qea/models/ea_diagram_object.rb', line 51

def bounding_box
  {
    top: recttop,
    left: rectleft,
    right: rectright,
    bottom: rectbottom,
    width: rectright - rectleft,
    height: rectbottom - recttop,
  }
end

#center_pointHash

Get the center point of the diagram object

Returns:

  • (Hash)

    Hash with :x, :y coordinates



64
65
66
67
68
69
# File 'lib/lutaml/qea/models/ea_diagram_object.rb', line 64

def center_point
  {
    x: (rectleft + rectright) / 2,
    y: (recttop + rectbottom) / 2,
  }
end

#parsed_styleHash

Parse ObjectStyle string into a hash

Returns:

  • (Hash)

    Parsed style attributes



73
74
75
76
77
78
79
80
# File 'lib/lutaml/qea/models/ea_diagram_object.rb', line 73

def parsed_style
  return {} unless objectstyle

  objectstyle.split(";").each_with_object({}) do |pair, hash|
    key, value = pair.split("=", 2)
    hash[key] = value if key && value
  end
end