Module: Uniword::Wordprocessingml::DocumentRoot::FeatureFacade
- Included in:
- Uniword::Wordprocessingml::DocumentRoot
- Defined in:
- lib/uniword/wordprocessingml/document_root/feature_facade.rb
Overview
Facade methods for CLI Vision features.
Provides convenience methods on DocumentRoot that delegate to specialized Manager classes. Each manager is lazily initialized and cached for the lifetime of the document.
Query methods return data; mutator methods return self for method chaining:
doc.add_comment(text: "Fix this", author: "Alice")
.add_watermark("DRAFT")
.insert_toc
.save("output.docx")
Instance Method Summary collapse
-
#accept_all_changes ⇒ self
Accept all tracked changes in the document.
-
#add_comment(text:, author:, initials: nil) ⇒ self
Add a comment to the document.
-
#add_footer(text, type: "default") ⇒ self
Add a footer to the document.
-
#add_header(text, type: "default") ⇒ self
Add a header to the document.
-
#add_watermark(text, color: "#808080", font_size: 72, font: "Segoe UI", opacity: ".5") ⇒ self
Add a text watermark to the document.
-
#clear_comments ⇒ self
Remove all comments from the document.
-
#diff(other_doc, text_only: false) ⇒ Uniword::Diff::DiffResult
Compare this document with another and return the differences.
-
#extract_images(output_dir) ⇒ Integer
Extract all images to a directory on disk.
-
#generate_toc(max_level: 6) ⇒ Array<Uniword::Toc::TocEntry>
Generate TOC entries from heading paragraphs.
-
#insert_image(image_path, **options) ⇒ self
Insert an image into the document.
-
#insert_toc(position: 0, max_level: 6) ⇒ self
Generate and insert a TOC into the document.
-
#list_comments ⇒ Array<Uniword::Comment>
List all comments in the document.
-
#list_footers ⇒ Array<Hash>
List footers with metadata (type, text, emptiness).
-
#list_headers ⇒ Array<Hash>
List headers with metadata (type, text, emptiness).
-
#list_images ⇒ Array<Uniword::Images::ImageInfo>
List all images in the document with metadata.
-
#list_watermarks ⇒ Array<String>
List all watermark texts in the document.
-
#protect(protection_type, password: nil) ⇒ self
Apply editing restriction to the document.
-
#protection_active? ⇒ Boolean
Check if the document has protection applied.
-
#protection_info ⇒ Hash?
Get current protection info.
-
#reject_all_changes ⇒ self
Reject all tracked changes in the document.
-
#remove_footers(type:) ⇒ self
Remove footers by type.
-
#remove_headers(type:) ⇒ self
Remove headers by type.
-
#remove_image(image_name) ⇒ self
Remove an image from the document by filename.
-
#remove_watermark ⇒ self
Remove all watermarks from the document.
-
#spellcheck(language: "en_US") ⇒ Uniword::Spellcheck::SpellcheckResult
Run spell and grammar checks on the document.
-
#unprotect ⇒ self
Remove all protection from the document.
-
#update_toc(max_level: 6) ⇒ self
Update an existing TOC in the document.
-
#watermark? ⇒ Boolean
Check if the document has any watermarks.
Instance Method Details
#accept_all_changes ⇒ self
Accept all tracked changes in the document.
45 46 47 48 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 45 def accept_all_changes review_manager.accept_all self end |
#add_comment(text:, author:, initials: nil) ⇒ self
Add a comment to the document.
36 37 38 39 40 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 36 def add_comment(text:, author:, initials: nil) review_manager.add_comment(text: text, author: , initials: initials) self end |
#add_footer(text, type: "default") ⇒ self
Add a footer to the document.
228 229 230 231 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 228 def (text, type: "default") .(text, type: type) self end |
#add_header(text, type: "default") ⇒ self
Add a header to the document.
218 219 220 221 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 218 def add_header(text, type: "default") .add_header(text, type: type) self end |
#add_watermark(text, color: "#808080", font_size: 72, font: "Segoe UI", opacity: ".5") ⇒ self
Add a text watermark to the document.
137 138 139 140 141 142 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 137 def add_watermark(text, color: "#808080", font_size: 72, font: "Segoe UI", opacity: ".5") watermark_manager.add(text, color: color, font_size: font_size, font: font, opacity: opacity) self end |
#clear_comments ⇒ self
Remove all comments from the document.
61 62 63 64 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 61 def clear_comments review_manager.clear_comments self end |
#diff(other_doc, text_only: false) ⇒ Uniword::Diff::DiffResult
Compare this document with another and return the differences.
73 74 75 76 77 78 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 73 def diff(other_doc, text_only: false) opts = {} opts[:text_only] = true if text_only Uniword::Diff::DocumentDiffer.new(self, other_doc, options: opts).diff end |
#extract_images(output_dir) ⇒ Integer
Extract all images to a directory on disk.
104 105 106 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 104 def extract_images(output_dir) image_manager.extract(output_dir) end |
#generate_toc(max_level: 6) ⇒ Array<Uniword::Toc::TocEntry>
Generate TOC entries from heading paragraphs.
172 173 174 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 172 def generate_toc(max_level: 6) toc_generator.generate(max_level: max_level) end |
#insert_image(image_path, **options) ⇒ self
Insert an image into the document.
113 114 115 116 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 113 def insert_image(image_path, **) image_manager.insert(image_path, **) self end |
#insert_toc(position: 0, max_level: 6) ⇒ self
Generate and insert a TOC into the document.
181 182 183 184 185 186 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 181 def insert_toc(position: 0, max_level: 6) entries = toc_generator.generate(max_level: max_level) toc_generator.insert(entries, position: position, max_level: max_level) self end |
#list_comments ⇒ Array<Uniword::Comment>
List all comments in the document.
26 27 28 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 26 def list_comments review_manager.list_comments end |
#list_footers ⇒ Array<Hash>
List footers with metadata (type, text, emptiness).
209 210 211 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 209 def . end |
#list_headers ⇒ Array<Hash>
List headers with metadata (type, text, emptiness).
202 203 204 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 202 def list_headers .list_headers end |
#list_images ⇒ Array<Uniword::Images::ImageInfo>
List all images in the document with metadata.
96 97 98 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 96 def list_images image_manager.list end |
#list_watermarks ⇒ Array<String>
List all watermark texts in the document.
162 163 164 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 162 def list_watermarks watermark_manager.list end |
#protect(protection_type, password: nil) ⇒ self
Apply editing restriction to the document.
259 260 261 262 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 259 def protect(protection_type, password: nil) protection_manager.apply(protection_type, password: password) self end |
#protection_active? ⇒ Boolean
Check if the document has protection applied.
275 276 277 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 275 def protection_active? protection_manager.protected? end |
#protection_info ⇒ Hash?
Get current protection info.
282 283 284 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 282 def protection_info protection_manager.info end |
#reject_all_changes ⇒ self
Reject all tracked changes in the document.
53 54 55 56 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 53 def reject_all_changes review_manager.reject_all self end |
#remove_footers(type:) ⇒ self
Remove footers by type.
246 247 248 249 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 246 def (type:) .(type: type) self end |
#remove_headers(type:) ⇒ self
Remove headers by type.
237 238 239 240 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 237 def remove_headers(type:) .remove_headers(type: type) self end |
#remove_image(image_name) ⇒ self
Remove an image from the document by filename.
122 123 124 125 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 122 def remove_image(image_name) image_manager.remove(image_name) self end |
#remove_watermark ⇒ self
Remove all watermarks from the document.
147 148 149 150 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 147 def remove_watermark watermark_manager.remove self end |
#spellcheck(language: "en_US") ⇒ Uniword::Spellcheck::SpellcheckResult
Run spell and grammar checks on the document.
86 87 88 89 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 86 def spellcheck(language: "en_US") Uniword::Spellcheck::SpellChecker.new(language: language) .check(self) end |
#unprotect ⇒ self
Remove all protection from the document.
267 268 269 270 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 267 def unprotect protection_manager.remove self end |
#update_toc(max_level: 6) ⇒ self
Update an existing TOC in the document.
192 193 194 195 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 192 def update_toc(max_level: 6) toc_generator.update(max_level: max_level) self end |
#watermark? ⇒ Boolean
Check if the document has any watermarks.
155 156 157 |
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 155 def watermark? watermark_manager.present? end |