Class: Lutaml::Xsd::Spa::Svg::LayoutEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/spa/svg/layout_engine.rb

Overview

Abstract base class for layout engines Subclasses must implement #calculate method

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ LayoutEngine

Returns a new instance of LayoutEngine.



15
16
17
# File 'lib/lutaml/xsd/spa/svg/layout_engine.rb', line 15

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/lutaml/xsd/spa/svg/layout_engine.rb', line 13

def config
  @config
end

Class Method Details

.for(config) ⇒ Object

Factory method to create appropriate layout engine



20
21
22
23
24
25
26
27
28
29
# File 'lib/lutaml/xsd/spa/svg/layout_engine.rb', line 20

def self.for(config)
  case config.layout_type
  when "tree"
    Lutaml::Xsd::Spa::Svg::Layouts::TreeLayout.new(config)
  when "vertical"
    Lutaml::Xsd::Spa::Svg::Layouts::VerticalLayout.new(config)
  else
    raise ArgumentError, "Unknown layout type: #{config.layout_type}"
  end
end

Instance Method Details

#calculate(component_data, component_type) ⇒ LayoutResult

Calculates layout for the given component data

Parameters:

  • component_data (Hash)

    The component data

  • component_type (Symbol)

    :element or :type

Returns:

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/lutaml/xsd/spa/svg/layout_engine.rb', line 35

def calculate(component_data, component_type)
  raise NotImplementedError, "#{self.class} must implement #calculate"
end