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

Instance Method Details

#accept_all_changesself

Accept all tracked changes in the document.

Returns:

  • (self)


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.

Parameters:

  • text (String)

    Comment text

  • author (String)

    Author name

  • initials (String, nil) (defaults to: nil)

    Author initials

Returns:

  • (self)


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: author,
                             initials: initials)
  self
end

Add a footer to the document.

Parameters:

  • text (String)

    Footer text content

  • type (String) (defaults to: "default")

    Footer type (default/first/even)

Returns:

  • (self)


228
229
230
231
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 228

def add_footer(text, type: "default")
  headers_footers_manager.add_footer(text, type: type)
  self
end

#add_header(text, type: "default") ⇒ self

Add a header to the document.

Parameters:

  • text (String)

    Header text content

  • type (String) (defaults to: "default")

    Header type (default/first/even)

Returns:

  • (self)


218
219
220
221
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 218

def add_header(text, type: "default")
  headers_footers_manager.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.

Parameters:

  • text (String)

    Watermark text

  • color (String) (defaults to: "#808080")

    Hex color (e.g., “#808080”)

  • font_size (Integer) (defaults to: 72)

    Font size in points

  • font (String) (defaults to: "Segoe UI")

    Font family name

  • opacity (String) (defaults to: ".5")

    Opacity value (e.g., “.5”)

Returns:

  • (self)


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_commentsself

Remove all comments from the document.

Returns:

  • (self)


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.

Parameters:

  • other_doc (DocumentRoot)

    The document to compare against

  • text_only (Boolean) (defaults to: false)

    Skip formatting comparison

Returns:



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.

Parameters:

  • output_dir (String)

    Target directory

Returns:

  • (Integer)

    Number of images extracted



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.

Parameters:

  • max_level (Integer) (defaults to: 6)

    Maximum heading level (1-6)

Returns:



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.

Parameters:

  • image_path (String)

    Path to the image file

  • options (Hash)

    See Images::ImageManager#insert

Returns:

  • (self)


113
114
115
116
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 113

def insert_image(image_path, **options)
  image_manager.insert(image_path, **options)
  self
end

#insert_toc(position: 0, max_level: 6) ⇒ self

Generate and insert a TOC into the document.

Parameters:

  • position (Integer) (defaults to: 0)

    Insert position (0 = beginning)

  • max_level (Integer) (defaults to: 6)

    Maximum heading level (1-6)

Returns:

  • (self)


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_commentsArray<Uniword::Comment>

List all comments in the document.

Returns:



26
27
28
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 26

def list_comments
  review_manager.list_comments
end

#list_footersArray<Hash>

List footers with metadata (type, text, emptiness).

Returns:

  • (Array<Hash>)


209
210
211
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 209

def list_footers
  headers_footers_manager.list_footers
end

#list_headersArray<Hash>

List headers with metadata (type, text, emptiness).

Returns:

  • (Array<Hash>)


202
203
204
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 202

def list_headers
  headers_footers_manager.list_headers
end

#list_imagesArray<Uniword::Images::ImageInfo>

List all images in the document with metadata.

Returns:



96
97
98
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 96

def list_images
  image_manager.list
end

#list_watermarksArray<String>

List all watermark texts in the document.

Returns:

  • (Array<String>)


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.

Parameters:

  • protection_type (Symbol)

    One of :read_only, :comments, :tracked_changes, :forms

  • password (String, nil) (defaults to: nil)

    Optional password

Returns:

  • (self)


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.

Returns:

  • (Boolean)


275
276
277
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 275

def protection_active?
  protection_manager.protected?
end

#protection_infoHash?

Get current protection info.

Returns:

  • (Hash, nil)


282
283
284
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 282

def protection_info
  protection_manager.info
end

#reject_all_changesself

Reject all tracked changes in the document.

Returns:

  • (self)


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.

Parameters:

  • type (String)

    Footer type (default/first/even)

Returns:

  • (self)


246
247
248
249
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 246

def remove_footers(type:)
  headers_footers_manager.remove_footers(type: type)
  self
end

#remove_headers(type:) ⇒ self

Remove headers by type.

Parameters:

  • type (String)

    Header type (default/first/even)

Returns:

  • (self)


237
238
239
240
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 237

def remove_headers(type:)
  headers_footers_manager.remove_headers(type: type)
  self
end

#remove_image(image_name) ⇒ self

Remove an image from the document by filename.

Parameters:

  • image_name (String)

    Filename (e.g., “image1.png”)

Returns:

  • (self)


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_watermarkself

Remove all watermarks from the document.

Returns:

  • (self)


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.

Parameters:

  • language (String) (defaults to: "en_US")

    Dictionary language (default: “en_US”)

Returns:



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

#unprotectself

Remove all protection from the document.

Returns:

  • (self)


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.

Parameters:

  • max_level (Integer) (defaults to: 6)

    Maximum heading level (1-6)

Returns:

  • (self)


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.

Returns:

  • (Boolean)


155
156
157
# File 'lib/uniword/wordprocessingml/document_root/feature_facade.rb', line 155

def watermark?
  watermark_manager.present?
end