Class: Uniword::Themes::ThemeTransformation

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/themes/theme_transformation.rb

Overview

Transforms between FriendlyTheme and WordTheme models.

This transformation is bidirectional:

  • to_word: Themes::Theme → Drawingml::Theme (for document generation)

  • from_word: Drawingml::Theme → Themes::Theme (for extraction/editing)

Architecture:

  • Stateless transformation (no instance state)

  • Follows Transformation pattern from lutaml-model

  • Separates concerns: models own serialization, this class owns conversion

Examples:

Convert friendly theme to Word theme

transformation = ThemeTransformation.new
word_theme = transformation.to_word(friendly_theme)

Extract friendly theme from Word theme

friendly = transformation.from_word(word_theme)

Full roundtrip

word_theme = transformation.to_word(friendly)
extracted = transformation.from_word(word_theme)
friendly.to_yaml == extracted.to_yaml  # => true (semantically)

Constant Summary collapse

COLOR_KEYS =

Standard color keys in a theme

%i[dk1 lt1 dk2 lt2 accent1 accent2 accent3 accent4 accent5 accent6 hlink
fol_hlink].freeze

Instance Method Summary collapse

Instance Method Details

#from_word(word_theme) ⇒ Themes::Theme

Transform Word theme to friendly theme

Parameters:

Returns:



47
48
49
50
51
52
53
# File 'lib/uniword/themes/theme_transformation.rb', line 47

def from_word(word_theme)
  Theme.new(
    name: word_theme.name,
    color_scheme: extract_color_scheme(word_theme),
    font_scheme: extract_font_scheme(word_theme),
  )
end

#to_word(friendly_theme) ⇒ Drawingml::Theme

Transform friendly theme to Word theme

Parameters:

Returns:



36
37
38
39
40
41
# File 'lib/uniword/themes/theme_transformation.rb', line 36

def to_word(friendly_theme)
  Drawingml::Theme.new(
    name: friendly_theme.name,
    theme_elements: build_theme_elements(friendly_theme),
  )
end