Class: Uniword::Docx::LocaleProfile

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

Overview

Locale profile: language → lang tags, separators, East Asian fonts.

Defines language-specific settings for DOCX generation. Loaded from config/locale_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(locale:, lang:, east_asia_lang:, bidi_lang:, decimal_symbol:, list_separator:, east_asian_font: nil, east_asian_light_font: nil) ⇒ LocaleProfile

Returns a new instance of LocaleProfile.



191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/uniword/docx/profile.rb', line 191

def initialize(locale:, lang:, east_asia_lang:, bidi_lang:,
               decimal_symbol:, list_separator:,
               east_asian_font: nil, east_asian_light_font: nil)
  @locale = locale
  @lang = lang
  @east_asia_lang = east_asia_lang
  @bidi_lang = bidi_lang
  @decimal_symbol = decimal_symbol
  @list_separator = list_separator
  @east_asian_font = east_asian_font
  @east_asian_light_font = east_asian_light_font
end

Instance Attribute Details

#bidi_langObject (readonly)

Returns the value of attribute bidi_lang.



187
188
189
# File 'lib/uniword/docx/profile.rb', line 187

def bidi_lang
  @bidi_lang
end

#decimal_symbolObject (readonly)

Returns the value of attribute decimal_symbol.



187
188
189
# File 'lib/uniword/docx/profile.rb', line 187

def decimal_symbol
  @decimal_symbol
end

#east_asia_langObject (readonly)

Returns the value of attribute east_asia_lang.



187
188
189
# File 'lib/uniword/docx/profile.rb', line 187

def east_asia_lang
  @east_asia_lang
end

#east_asian_fontObject (readonly)

Returns the value of attribute east_asian_font.



187
188
189
# File 'lib/uniword/docx/profile.rb', line 187

def east_asian_font
  @east_asian_font
end

#east_asian_light_fontObject (readonly)

Returns the value of attribute east_asian_light_font.



187
188
189
# File 'lib/uniword/docx/profile.rb', line 187

def east_asian_light_font
  @east_asian_light_font
end

#langObject (readonly)

Returns the value of attribute lang.



187
188
189
# File 'lib/uniword/docx/profile.rb', line 187

def lang
  @lang
end

#list_separatorObject (readonly)

Returns the value of attribute list_separator.



187
188
189
# File 'lib/uniword/docx/profile.rb', line 187

def list_separator
  @list_separator
end

#localeObject (readonly)

Returns the value of attribute locale.



187
188
189
# File 'lib/uniword/docx/profile.rb', line 187

def locale
  @locale
end

Class Method Details

.available_localesObject

List all available locales



220
221
222
223
# File 'lib/uniword/docx/profile.rb', line 220

def self.available_locales
  path = File.join(CONFIG_DIR, "locale_profiles.yml")
  YAML.load_file(path)["locales"].keys.sort
end

.from_locale(locale_code) ⇒ Object

Load from config/locale_profiles.yml



205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/uniword/docx/profile.rb', line 205

def self.from_locale(locale_code)
  path = File.join(CONFIG_DIR, "locale_profiles.yml")
  all = YAML.load_file(path)["locales"]

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

  data = all[locale_code]
  new(locale: locale_code, **data.transform_keys(&:to_sym))
end