Class: Uniword::Stylesets::Package
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Stylesets::Package
- Defined in:
- lib/uniword/stylesets/package.rb
Overview
Represents a .dotx StyleSet package (ZIP with word/styles.xml)
Follows MODEL-DRIVEN architecture using lutaml-model for XML deserialization. No manual parsing.
Class Method Summary collapse
-
.extract_zip(path) ⇒ Hash
Extract ZIP contents.
-
.from_file(path) ⇒ Package
Load Package from .dotx file.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Package
constructor
Initialize Package.
-
#styleset ⇒ StyleSet
Convert to StyleSet model.
Constructor Details
#initialize(attributes = {}) ⇒ Package
Initialize Package
26 27 28 29 |
# File 'lib/uniword/stylesets/package.rb', line 26 def initialize(attributes = {}) super @styles_configuration ||= Uniword::Wordprocessingml::StylesConfiguration.new end |
Class Method Details
.extract_zip(path) ⇒ Hash
Extract ZIP contents
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/uniword/stylesets/package.rb', line 80 def self.extract_zip(path) require "zip" contents = {} Zip::File.open(path) do |zip| zip.each do |entry| next if entry.directory? contents[entry.name] = entry.get_input_stream.read end end contents rescue Zip::Error => e raise Uniword::CorruptedFileError.new(path, "Failed to extract: #{e.}") end |
.from_file(path) ⇒ Package
Load Package from .dotx file
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/uniword/stylesets/package.rb', line 40 def self.from_file(path) # Validate file exists raise Uniword::FileNotFoundError, path unless File.exist?(path) # Extract ZIP extracted = extract_zip(path) # Deserialize styles.xml using lutaml-model (MODEL-DRIVEN!) styles_xml = extracted["word/styles.xml"] unless styles_xml raise Uniword::CorruptedFileError.new(path, "styles.xml missing") end styles_config = Uniword::Wordprocessingml::StylesConfiguration.from_xml(styles_xml) # Create Package instance new( styles_configuration: styles_config, source_path: path, ) end |