Class: Uniword::Docx::SystemProfile

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

Overview

System profile: Word version → fonts, theme, compat settings.

Defines what Word version to target when generating DOCX output. Loaded from config/system_profiles.yml.

Constant Summary collapse

CONFIG_DIR =
File.join(__dir__, "../../../config")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, compat_mode:, font_scheme_name:, application_name:, app_version:, default_theme_name: nil, **_opts) ⇒ SystemProfile

Returns a new instance of SystemProfile.



135
136
137
138
139
140
141
142
143
# File 'lib/uniword/docx/profile.rb', line 135

def initialize(name:, compat_mode:, font_scheme_name:,
               application_name:, app_version:, default_theme_name: nil, **_opts)
  @name = name
  @compat_mode = compat_mode
  @font_scheme_name = font_scheme_name
  @default_theme_name = default_theme_name
  @application_name = application_name
  @app_version = app_version
end

Instance Attribute Details

#app_versionObject (readonly)

Returns the value of attribute app_version.



132
133
134
# File 'lib/uniword/docx/profile.rb', line 132

def app_version
  @app_version
end

#application_nameObject (readonly)

Returns the value of attribute application_name.



132
133
134
# File 'lib/uniword/docx/profile.rb', line 132

def application_name
  @application_name
end

#compat_modeObject (readonly)

Returns the value of attribute compat_mode.



132
133
134
# File 'lib/uniword/docx/profile.rb', line 132

def compat_mode
  @compat_mode
end

#default_theme_nameObject (readonly)

Returns the value of attribute default_theme_name.



132
133
134
# File 'lib/uniword/docx/profile.rb', line 132

def default_theme_name
  @default_theme_name
end

#font_scheme_nameObject (readonly)

Returns the value of attribute font_scheme_name.



132
133
134
# File 'lib/uniword/docx/profile.rb', line 132

def font_scheme_name
  @font_scheme_name
end

#nameObject (readonly)

Returns the value of attribute name.



132
133
134
# File 'lib/uniword/docx/profile.rb', line 132

def name
  @name
end

Class Method Details

.defaultsObject

Default: Office 2024



170
171
172
# File 'lib/uniword/docx/profile.rb', line 170

def self.defaults
  load("office_2024")
end

.load(name) ⇒ Object

Load from config/system_profiles.yml



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/uniword/docx/profile.rb', line 146

def self.load(name)
  path = File.join(CONFIG_DIR, "system_profiles.yml")
  all = YAML.load_file(path)["profiles"]

  unless all.key?(name)
    raise ArgumentError,
          "System profile '#{name}' not found. " \
          "Available: #{all.keys.join(', ')}"
  end

  data = all[name]
  # Rename YAML keys to match constructor parameter names
  if data.key?("font_scheme")
    data["font_scheme_name"] =
      data.delete("font_scheme")
  end
  if data.key?("default_theme")
    data["default_theme_name"] =
      data.delete("default_theme")
  end
  new(name: name, **data.transform_keys(&:to_sym))
end

Instance Method Details

#font_schemeObject

Lazily loaded font scheme



175
176
177
# File 'lib/uniword/docx/profile.rb', line 175

def font_scheme
  @font_scheme ||= Resource::FontSchemeLoader.load(font_scheme_name)
end