Class: Uniword::Docx::Profile

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

Overview

Composition of three independent profile axes:

SystemProfile  "What Word version to target"
LocaleProfile   "What locale/language to use"
UserProfile     "Who is creating this document"

Used by Reconciler to populate DOCX parts with Word-expected content.

Examples:

Create from preset

profile = Profile.load(:word_2024_en)

Create with custom user

profile = Profile.load(:word_2024_en,
  user: UserProfile.new(name: "Ada Lovelace"))

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(system:, locale:, user: UserProfile.defaults) ⇒ Profile

Returns a new instance of Profile.



27
28
29
30
31
# File 'lib/uniword/docx/profile.rb', line 27

def initialize(system:, locale:, user: UserProfile.defaults)
  @system = system
  @locale = locale
  @user = user
end

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale.



25
26
27
# File 'lib/uniword/docx/profile.rb', line 25

def locale
  @locale
end

#systemObject (readonly)

Returns the value of attribute system.



25
26
27
# File 'lib/uniword/docx/profile.rb', line 25

def system
  @system
end

#userObject (readonly)

Returns the value of attribute user.



25
26
27
# File 'lib/uniword/docx/profile.rb', line 25

def user
  @user
end

Class Method Details

.defaultsObject

Default profile (Office 2024, en-US)



55
56
57
58
59
60
61
# File 'lib/uniword/docx/profile.rb', line 55

def self.defaults
  new(
    system: SystemProfile.defaults,
    locale: LocaleProfile.from_locale("en"),
    user: UserProfile.defaults,
  )
end

.load(name, user: nil) ⇒ Profile

Load a named preset from config/profiles.yml

Parameters:

  • name (Symbol, String)

    Preset name (e.g., :word_2024_en)

  • user (UserProfile) (defaults to: nil)

    Optional user override

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/uniword/docx/profile.rb', line 38

def self.load(name, user: nil)
  presets = load_presets
  key = name.to_s

  unless presets.key?(key)
    raise ArgumentError,
          "Profile preset '#{key}' not found. " \
          "Available: #{presets.keys.join(', ')}"
  end

  preset = presets[key]
  sys = SystemProfile.load(preset["system"])
  loc = LocaleProfile.from_locale(preset["locale"])
  new(system: sys, locale: loc, user: user || UserProfile.defaults)
end

Instance Method Details

#app_versionObject



104
105
106
# File 'lib/uniword/docx/profile.rb', line 104

def app_version
  system.app_version
end

#application_nameObject



100
101
102
# File 'lib/uniword/docx/profile.rb', line 100

def application_name
  system.application_name
end

#bidi_langObject



80
81
82
# File 'lib/uniword/docx/profile.rb', line 80

def bidi_lang
  locale.bidi_lang
end

#body_fontObject

Delegate common values to sub-profiles



64
65
66
# File 'lib/uniword/docx/profile.rb', line 64

def body_font
  system.font_scheme&.minor_font
end

#compat_modeObject



108
109
110
# File 'lib/uniword/docx/profile.rb', line 108

def compat_mode
  system.compat_mode
end

#decimal_symbolObject



84
85
86
# File 'lib/uniword/docx/profile.rb', line 84

def decimal_symbol
  locale.decimal_symbol
end

#east_asia_langObject



76
77
78
# File 'lib/uniword/docx/profile.rb', line 76

def east_asia_lang
  locale.east_asia_lang
end

#heading_fontObject



68
69
70
# File 'lib/uniword/docx/profile.rb', line 68

def heading_font
  system.font_scheme&.major_font
end

#langObject



72
73
74
# File 'lib/uniword/docx/profile.rb', line 72

def lang
  locale.lang
end

#list_separatorObject



88
89
90
# File 'lib/uniword/docx/profile.rb', line 88

def list_separator
  locale.list_separator
end

#theme_font_langObject



112
113
114
# File 'lib/uniword/docx/profile.rb', line 112

def theme_font_lang
  { val: locale.lang, east_asia: locale.east_asia_lang }
end

#user_companyObject



96
97
98
# File 'lib/uniword/docx/profile.rb', line 96

def user_company
  user.company
end

#user_nameObject



92
93
94
# File 'lib/uniword/docx/profile.rb', line 92

def user_name
  user.name
end