Class: Uniword::Generation::StyleExtractor
- Inherits:
-
Object
- Object
- Uniword::Generation::StyleExtractor
- Defined in:
- lib/uniword/generation/style_extractor.rb
Overview
Extracts styles from DOCX files into serializable format.
Reads styles from an existing DOCX via DocumentFactory and produces a plain hash representation suitable for YAML serialization.
Class Method Summary collapse
-
.extract_from_docx(docx_path) ⇒ Hash
Extract styles from a DOCX file as a hash.
-
.extract_to_yaml(docx_path, output_path) ⇒ void
Extract styles from a DOCX file and write to YAML.
Class Method Details
.extract_from_docx(docx_path) ⇒ Hash
Extract styles from a DOCX file as a hash.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/uniword/generation/style_extractor.rb', line 23 def self.extract_from_docx(docx_path) validate_path(docx_path) doc = DocumentFactory.from_file(docx_path) config = doc.styles_configuration styles_data = config.styles.map do |style| style_to_hash(style) end { name: extract_name(docx_path), source_file: File.basename(docx_path), styles: styles_data, } end |
.extract_to_yaml(docx_path, output_path) ⇒ void
This method returns an undefined value.
Extract styles from a DOCX file and write to YAML.
45 46 47 48 49 50 51 52 |
# File 'lib/uniword/generation/style_extractor.rb', line 45 def self.extract_to_yaml(docx_path, output_path) data = extract_from_docx(docx_path) dir = File.dirname(output_path) FileUtils.mkdir_p(dir) File.write(output_path, YAML.dump(stringify_keys(data))) end |