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:



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

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



23
24
25
# File 'lib/lutaml/qea/models/ea_diagram_object.rb', line 23

def self.primary_key_column
  :instance_id
end

.table_nameObject



27
28
29
# File 'lib/lutaml/qea/models/ea_diagram_object.rb', line 27

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



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

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



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

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



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

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