Class: Lutaml::Ea::Diagram::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/ea/diagram/configuration.rb

Overview

Configuration management for diagram styling

This class provides hierarchical style resolution with the following priority:

  1. EA Data (QEA/XMI) - Highest priority

  2. Class-specific overrides (user config)

  3. Package-based styling (wildcard support)

  4. Stereotype-based styling

  5. Global defaults - Lowest priority

Examples:

config = Configuration.new("config/diagram_styles.yml")
fill_color = config.style_for(element, "colors.fill")
font_family = config.style_for(element, "fonts.class_name.family")

Constant Summary collapse

DEFAULT_CONFIG_PATHS =

Default configuration file paths in order of preference

[
  "config/diagram_styles.yml",
  File.expand_path("~/.lutaml/diagram_styles.yml"),
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path = nil) ⇒ Configuration

Initialize configuration with optional custom path

Parameters:

  • config_path (String, nil) (defaults to: nil)

    Path to custom configuration file



34
35
36
# File 'lib/lutaml/ea/diagram/configuration.rb', line 34

def initialize(config_path = nil)
  @config_data = load_configuration(config_path)
end

Instance Attribute Details

#config_dataObject (readonly)

Returns the value of attribute config_data.



23
24
25
# File 'lib/lutaml/ea/diagram/configuration.rb', line 23

def config_data
  @config_data
end

Instance Method Details

#connector_style(connector_type, property) ⇒ Object

Get connector style

Type of connector (generalization, association, etc.)

Parameters:

  • connector_type (String)
  • property (String)

    Style property path

Returns:

  • (Object)

    Style value



107
108
109
# File 'lib/lutaml/ea/diagram/configuration.rb', line 107

def connector_style(connector_type, property)
  dig_config("connectors.#{connector_type}.#{property}")
end

#legend_configHash

Get legend configuration

Returns:

  • (Hash)

    Legend configuration



114
115
116
# File 'lib/lutaml/ea/diagram/configuration.rb', line 114

def legend_config
  config_data["legend"] || {}
end

#style_for(element, property) ⇒ Object

Get style for a specific element

Parameters:

  • element (Lutaml::Uml::Class, Object)

    UML element

  • property (String)

    Style property path (e.g., “colors.fill”)

Returns:

  • (Object)

    Style value



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/lutaml/ea/diagram/configuration.rb', line 43

def style_for(element, property) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  return nil if property.nil? || property.empty?

  # Priority: Class-specific > Package > Stereotype > Defaults
  value = nil

  # 1. Try class-specific override (highest priority)
  if element.respond_to?(:name) && element.name
    class_config = dig_config("classes.#{element.name}.#{property}")
    value = class_config if class_config
  end

  # 2. Try package-based styling
  if !value &&
      element.respond_to?(:package_name) && element.package_name
    # Support wildcards: "CityGML::*"
    package_configs = config_data["packages"] || {}
    package_configs.each do |pattern, pkg_config|
      if matches_package?(element.package_name, pattern)
        pkg_value = dig_hash(pkg_config, property)
        value = pkg_value if pkg_value
        break
      end
    end
  end

  # 3. Try stereotype-based styling
  if !value && element.respond_to?(:stereotype) && element.stereotype
    stereotypes = Array(element.stereotype)
    stereotypes.each do |stereo|
      stereo_value = dig_config("stereotypes.#{stereo}.#{property}")
      if stereo_value
        value = stereo_value
        break
      end
    end
  end

  # 4. Fall back to defaults (lowest priority)
  # Handle property name aliases
  # (e.g., "colors.fill" -> "colors.default_fill")
  unless value
    value = dig_config("defaults.#{property}")

    # If not found, try with "default_" prefix for certain properties
    unless value
      if property.start_with?("colors.fill")
        value = dig_config("defaults.colors.default_fill")
      elsif property.start_with?("colors.stroke") &&
          !property.include?("stroke_")
        value = dig_config("defaults.colors.default_stroke")
      end
    end
  end

  value
end

#to_hHash

Get the entire configuration data

Returns:

  • (Hash)

    Complete configuration data



121
122
123
# File 'lib/lutaml/ea/diagram/configuration.rb', line 121

def to_h
  config_data
end