Class: Uniword::Generation::StyleMapper
- Inherits:
-
Object
- Object
- Uniword::Generation::StyleMapper
- 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).
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
-
#default_paragraph_style ⇒ String
Default paragraph style name.
-
#initialize(mapping_config = nil) ⇒ StyleMapper
constructor
Initialize with a mapping config path.
-
#mappings ⇒ Hash
All loaded mappings.
-
#style_for(element_type, _context = {}) ⇒ String
Look up the OOXML style name for a semantic element type.
Constructor Details
#initialize(mapping_config = nil) ⇒ StyleMapper
Initialize with a mapping config path.
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_style ⇒ String
Default paragraph style name.
57 58 59 |
# File 'lib/uniword/generation/style_mapper.rb', line 57 def default_paragraph_style @mapping["body"] || "Normal" end |
#mappings ⇒ Hash
All loaded mappings.
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.
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 |