Class: Uniword::Toc::TocEntry
- Inherits:
-
Object
- Object
- Uniword::Toc::TocEntry
- Defined in:
- lib/uniword/toc/toc_entry.rb
Overview
Value object representing a single entry in a Table of Contents.
Each entry corresponds to a heading paragraph found in the document. Holds the heading level, text, page number (if known), style name, and the paragraph index within the document body.
Instance Attribute Summary collapse
-
#level ⇒ Integer
readonly
Heading level (1-6).
-
#page ⇒ Integer?
readonly
Page number (populated by Word after update).
-
#paragraph_index ⇒ Integer?
readonly
Index of the paragraph in the document body.
-
#style_name ⇒ String?
readonly
Style name that produced this entry.
-
#text ⇒ String
readonly
Heading text content.
Instance Method Summary collapse
-
#initialize(level:, text:, page: nil, style_name: nil, paragraph_index: nil) ⇒ TocEntry
constructor
Initialize a TOC entry.
-
#to_h ⇒ Hash
Convert to a hash suitable for JSON output.
-
#to_s ⇒ String
Human-readable representation.
Constructor Details
#initialize(level:, text:, page: nil, style_name: nil, paragraph_index: nil) ⇒ TocEntry
Initialize a TOC entry.
41 42 43 44 45 46 47 48 |
# File 'lib/uniword/toc/toc_entry.rb', line 41 def initialize(level:, text:, page: nil, style_name: nil, paragraph_index: nil) @level = level @text = text @page = page @style_name = style_name @paragraph_index = paragraph_index end |
Instance Attribute Details
#level ⇒ Integer (readonly)
Returns Heading level (1-6).
20 21 22 |
# File 'lib/uniword/toc/toc_entry.rb', line 20 def level @level end |
#page ⇒ Integer? (readonly)
Returns Page number (populated by Word after update).
26 27 28 |
# File 'lib/uniword/toc/toc_entry.rb', line 26 def page @page end |
#paragraph_index ⇒ Integer? (readonly)
Returns Index of the paragraph in the document body.
32 33 34 |
# File 'lib/uniword/toc/toc_entry.rb', line 32 def paragraph_index @paragraph_index end |
#style_name ⇒ String? (readonly)
Returns Style name that produced this entry.
29 30 31 |
# File 'lib/uniword/toc/toc_entry.rb', line 29 def style_name @style_name end |
#text ⇒ String (readonly)
Returns Heading text content.
23 24 25 |
# File 'lib/uniword/toc/toc_entry.rb', line 23 def text @text end |
Instance Method Details
#to_h ⇒ Hash
Convert to a hash suitable for JSON output.
62 63 64 65 66 67 68 69 70 |
# File 'lib/uniword/toc/toc_entry.rb', line 62 def to_h { level: level, text: text, page: page, style_name: style_name, paragraph_index: paragraph_index, } end |
#to_s ⇒ String
Human-readable representation.
53 54 55 56 57 |
# File 'lib/uniword/toc/toc_entry.rb', line 53 def to_s indent = " " * (level - 1) page_str = page ? " (p.#{page})" : "" "#{indent}#{text}#{page_str}" end |