Class: Uniword::Assembly::TocEntry
- Inherits:
-
Object
- Object
- Uniword::Assembly::TocEntry
- Defined in:
- lib/uniword/assembly/toc_entry.rb
Overview
Represents a single entry in the Table of Contents.
Each entry contains the heading text, level, and reference to the source paragraph.
Instance Attribute Summary collapse
-
#bookmark_name ⇒ String?
readonly
The bookmark name for linking.
-
#level ⇒ Integer
readonly
The heading level (1-9).
-
#page_number ⇒ Integer?
readonly
The page number (placeholder, updated by Word).
-
#paragraph_index ⇒ Integer
readonly
The paragraph index in the document.
-
#text ⇒ String
readonly
The heading text.
Instance Method Summary collapse
-
#initialize(text:, level:, paragraph_index:, bookmark_name: nil, page_number: nil) ⇒ TocEntry
constructor
Initialize a TOC entry.
-
#to_paragraph(include_page_numbers: true) ⇒ Wordprocessingml::Paragraph
Create a paragraph for this TOC entry.
Constructor Details
#initialize(text:, level:, paragraph_index:, bookmark_name: nil, page_number: nil) ⇒ TocEntry
Initialize a TOC entry.
38 39 40 41 42 43 44 45 |
# File 'lib/uniword/assembly/toc_entry.rb', line 38 def initialize(text:, level:, paragraph_index:, bookmark_name: nil, page_number: nil) @text = text @level = level @paragraph_index = paragraph_index @bookmark_name = bookmark_name @page_number = page_number end |
Instance Attribute Details
#bookmark_name ⇒ String? (readonly)
Returns The bookmark name for linking.
26 27 28 |
# File 'lib/uniword/assembly/toc_entry.rb', line 26 def bookmark_name @bookmark_name end |
#level ⇒ Integer (readonly)
Returns The heading level (1-9).
20 21 22 |
# File 'lib/uniword/assembly/toc_entry.rb', line 20 def level @level end |
#page_number ⇒ Integer? (readonly)
Returns The page number (placeholder, updated by Word).
29 30 31 |
# File 'lib/uniword/assembly/toc_entry.rb', line 29 def page_number @page_number end |
#paragraph_index ⇒ Integer (readonly)
Returns The paragraph index in the document.
23 24 25 |
# File 'lib/uniword/assembly/toc_entry.rb', line 23 def paragraph_index @paragraph_index end |
#text ⇒ String (readonly)
Returns The heading text.
17 18 19 |
# File 'lib/uniword/assembly/toc_entry.rb', line 17 def text @text end |
Instance Method Details
#to_paragraph(include_page_numbers: true) ⇒ Wordprocessingml::Paragraph
Create a paragraph for this TOC entry.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/uniword/assembly/toc_entry.rb', line 51 def to_paragraph(include_page_numbers: true) para = Wordprocessingml::Paragraph.new para.properties ||= Wordprocessingml::ParagraphProperties.new para.properties.style = "TOC#{@level}" # Add indentation based on level (360 twips = 0.25 inch per level) para.properties.indentation ||= Properties::Indentation.new para.properties.indentation.left = (@level - 1) * 360 # Add hyperlink if bookmark exists if @bookmark_name add_hyperlink_entry(para, include_page_numbers) else add_simple_entry(para, include_page_numbers) end para end |