Class: Uniword::StyleSet
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::StyleSet
- Defined in:
- lib/uniword/styleset.rb
Overview
Represents a StyleSet containing a collection of style definitions
StyleSets are named collections of paragraph, character, table, and numbering styles that provide consistent formatting for Word documents. They work in conjunction with themes to create professionally styled documents.
Class Method Summary collapse
-
.available_stylesets ⇒ Array<String>
List all available bundled StyleSets.
-
.from_dotx(path) ⇒ StyleSet
Load StyleSet from .dotx file.
-
.load(name) ⇒ StyleSet
Load bundled StyleSet by name.
Instance Method Summary collapse
-
#apply_to(document, strategy: :keep_existing) ⇒ void
Apply this StyleSet to a document.
-
#character_styles ⇒ Array<Style>
Get character styles.
-
#count ⇒ Integer
Get the number of styles.
-
#initialize(attributes = {}) ⇒ StyleSet
constructor
Initialize StyleSet.
-
#inspect ⇒ String
Provide detailed inspection for debugging.
-
#paragraph_styles ⇒ Array<Style>
Get paragraph styles.
-
#styles_by_type(type) ⇒ Array<Style>
Get styles by type.
-
#table_styles ⇒ Array<Style>
Get table styles.
-
#valid? ⇒ Boolean
Check if StyleSet is valid.
Constructor Details
#initialize(attributes = {}) ⇒ StyleSet
Initialize StyleSet
39 40 41 42 43 |
# File 'lib/uniword/styleset.rb', line 39 def initialize(attributes = {}) super @styles ||= [] @source_file ||= nil end |
Class Method Details
.available_stylesets ⇒ Array<String>
List all available bundled StyleSets
127 128 129 |
# File 'lib/uniword/styleset.rb', line 127 def self.available_stylesets Stylesets::YamlStyleSetLoader.available_stylesets end |
.from_dotx(path) ⇒ StyleSet
Load StyleSet from .dotx file
105 106 107 |
# File 'lib/uniword/styleset.rb', line 105 def self.from_dotx(path) Stylesets::Package.from_file(path).styleset end |
.load(name) ⇒ StyleSet
Load bundled StyleSet by name
116 117 118 |
# File 'lib/uniword/styleset.rb', line 116 def self.load(name) Stylesets::YamlStyleSetLoader.load_bundled(name) end |
Instance Method Details
#apply_to(document, strategy: :keep_existing) ⇒ void
This method returns an undefined value.
Apply this StyleSet to a document
Merges all styles from this StyleSet into the document’s styles configuration.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/uniword/styleset.rb', line 142 def apply_to(document, strategy: :keep_existing) return unless document.respond_to?(:styles_configuration) styles.each do |style| case strategy when :replace document.styles_configuration.add_style(style.dup, allow_overwrite: true) when :keep_existing document.styles_configuration.add_style(style.dup) unless document.styles_configuration.style_exists?(style.id) when :rename if document.styles_configuration.style_exists?(style.id) new_style = style.dup new_style.id = "#{style.id}_styleset" document.styles_configuration.add_style(new_style) else document.styles_configuration.add_style(style.dup) end else raise ArgumentError, "Invalid strategy: #{strategy}" end end end |
#character_styles ⇒ Array<Style>
Get character styles
78 79 80 |
# File 'lib/uniword/styleset.rb', line 78 def character_styles styles_by_type("character") end |
#count ⇒ Integer
Get the number of styles
48 49 50 |
# File 'lib/uniword/styleset.rb', line 48 def count styles.size end |
#inspect ⇒ String
Provide detailed inspection for debugging
92 93 94 95 96 |
# File 'lib/uniword/styleset.rb', line 92 def inspect "#<Uniword::StyleSet name=#{name.inspect} " \ "styles=#{styles.count} " \ "source=#{source_file.inspect}>" end |
#paragraph_styles ⇒ Array<Style>
Get paragraph styles
71 72 73 |
# File 'lib/uniword/styleset.rb', line 71 def paragraph_styles styles_by_type("paragraph") end |
#styles_by_type(type) ⇒ Array<Style>
Get styles by type
63 64 65 66 |
# File 'lib/uniword/styleset.rb', line 63 def styles_by_type(type) type_str = type.to_s styles.select { |s| s.type == type_str } end |
#table_styles ⇒ Array<Style>
Get table styles
85 86 87 |
# File 'lib/uniword/styleset.rb', line 85 def table_styles styles_by_type("table") end |
#valid? ⇒ Boolean
Check if StyleSet is valid
55 56 57 |
# File 'lib/uniword/styleset.rb', line 55 def valid? !name.nil? && !name.empty? && styles.is_a?(Array) end |