Class: Uniword::Generation::StyleMapper

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

Overview

Maps semantic element types to OOXML style names.

Loads mapping configuration from YAML files and provides lookup for style names based on semantic element types (e.g., heading_1 maps to “Heading1” in ISO Publication style).

Examples:

Create mapper with ISO config

mapper = StyleMapper.new("config/style_mappings/iso_publication.yml")
mapper.style_for("heading_1")  # => "Heading1"
mapper.style_for("body")       # => "Body Text"

Constant Summary collapse

DEFAULT_MAPPING =
{
  "heading_1" => "Heading1",
  "heading_2" => "Heading2",
  "heading_3" => "Heading3",
  "heading_4" => "Heading4",
  "heading_5" => "Heading5",
  "heading_6" => "Heading6",
  "body" => "Normal",
  "note" => "Note",
  "example" => "Example",
  "table_title" => "TableTitle",
  "figure_title" => "FigureTitle",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(mapping_config = nil) ⇒ StyleMapper

Initialize with a mapping config path.

Parameters:

  • mapping_config (String, nil) (defaults to: nil)

    Path to YAML mapping file. Falls back to DEFAULT_MAPPING when nil.



36
37
38
39
40
41
42
# File 'lib/uniword/generation/style_mapper.rb', line 36

def initialize(mapping_config = nil)
  @mapping = if mapping_config && File.exist?(mapping_config)
               load_mapping(mapping_config)
             else
               DEFAULT_MAPPING.dup
             end
end

Instance Method Details

#default_paragraph_styleString

Default paragraph style name.

Returns:

  • (String)

    The default body style name



57
58
59
# File 'lib/uniword/generation/style_mapper.rb', line 57

def default_paragraph_style
  @mapping["body"] || "Normal"
end

#mappingsHash

All loaded mappings.

Returns:

  • (Hash)

    The full mapping hash



64
65
66
# File 'lib/uniword/generation/style_mapper.rb', line 64

def mappings
  @mapping.dup
end

#style_for(element_type, _context = {}) ⇒ String

Look up the OOXML style name for a semantic element type.

Parameters:

  • element_type (String)

    Semantic element type (e.g., “heading_1”, “body”, “note”)

  • context (Hash)

    Optional context for disambiguation

Returns:

  • (String)

    OOXML style name



50
51
52
# File 'lib/uniword/generation/style_mapper.rb', line 50

def style_for(element_type, _context = {})
  @mapping[element_type.to_s] || default_for(element_type)
end