Class: Uniword::ThemeWriter

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

Overview

Writer for saving Theme instances to files.

Responsibility: Handle theme file writing operations. Follows Single Responsibility Principle - separated from Theme class.

Examples:

Save theme to .thmx file

writer = ThemeWriter.new(theme)
writer.save('output.thmx')

Save with explicit format

writer = ThemeWriter.new(theme)
writer.save('output.thmx', format: :thmx)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme) ⇒ ThemeWriter

Initialize writer with a theme.

Parameters:

  • theme (Theme)

    The theme to write



22
23
24
# File 'lib/uniword/theme_writer.rb', line 22

def initialize(theme)
  @theme = theme
end

Instance Attribute Details

#themeObject (readonly)

Returns the value of attribute theme.



17
18
19
# File 'lib/uniword/theme_writer.rb', line 17

def theme
  @theme
end

Instance Method Details

#save(path, format: :auto) ⇒ void

This method returns an undefined value.

Save theme to file.

Parameters:

  • path (String)

    Output path

  • format (Symbol) (defaults to: :auto)

    Format to save as (:auto, :thmx)



31
32
33
34
35
36
37
38
39
40
# File 'lib/uniword/theme_writer.rb', line 31

def save(path, format: :auto)
  format = infer_format(path) if format == :auto

  case format
  when :thmx
    Ooxml::ThmxPackage.to_file(theme, path)
  else
    raise ArgumentError, "Unsupported format for theme: #{format}"
  end
end