Class: Uniword::Assembly::TocInstruction
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Assembly::TocInstruction
- Defined in:
- lib/uniword/assembly/toc_instruction.rb
Overview
Table of Contents field instruction.
Represents the TOC field code that Word uses to generate and update TOC. Example field code: { TOC o “1-3” h z u }
Class Method Summary collapse
-
.parse(str) ⇒ TocInstruction
Parse a TOC field instruction string.
Instance Method Summary collapse
-
#hidden_formats ⇒ Boolean
Use hidden formats.
-
#hyperlinks ⇒ Boolean
Include hyperlinks in TOC.
-
#leader ⇒ String?
Custom leader.
-
#outline_levels ⇒ String?
Outline levels to include (e.g., “1-3”).
-
#preserve_tabs ⇒ Boolean
Preserve tab stops.
-
#separator ⇒ String?
Custom separator.
-
#to_s ⇒ String
Generate the field instruction string.
-
#use_paragraph_outline ⇒ Boolean
Use paragraph outline level.
Class Method Details
.parse(str) ⇒ TocInstruction
Parse a TOC field instruction string.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/uniword/assembly/toc_instruction.rb', line 68 def self.parse(str) return nil if str.nil? || str.strip.empty? instr = new # Parse outline levels: \o "1-3" instr.outline_levels = ::Regexp.last_match(1) if str =~ /\\o\s+"([^"]+)"/ # Parse switches instr.hyperlinks = str.include?('\\h') instr.hidden_formats = str.include?('\\z') instr.use_paragraph_outline = str.include?('\\u') instr.preserve_tabs = str.include?('\\w') # Parse separator: \s "separator" instr.separator = ::Regexp.last_match(1) if str =~ /\\s\s+"([^"]+)"/ # Parse leader: \l "leader" instr.leader = ::Regexp.last_match(1) if str =~ /\\l\s+"([^"]+)"/ instr end |
Instance Method Details
#hidden_formats ⇒ Boolean
Returns Use hidden formats.
27 |
# File 'lib/uniword/assembly/toc_instruction.rb', line 27 attribute :hidden_formats, :boolean, default: -> { true } |
#hyperlinks ⇒ Boolean
Returns Include hyperlinks in TOC.
24 |
# File 'lib/uniword/assembly/toc_instruction.rb', line 24 attribute :hyperlinks, :boolean, default: -> { true } |
#leader ⇒ String?
Returns Custom leader.
39 |
# File 'lib/uniword/assembly/toc_instruction.rb', line 39 attribute :leader, :string |
#outline_levels ⇒ String?
Returns Outline levels to include (e.g., “1-3”).
21 |
# File 'lib/uniword/assembly/toc_instruction.rb', line 21 attribute :outline_levels, :string |
#preserve_tabs ⇒ Boolean
Returns Preserve tab stops.
33 |
# File 'lib/uniword/assembly/toc_instruction.rb', line 33 attribute :preserve_tabs, :boolean, default: -> { false } |
#separator ⇒ String?
Returns Custom separator.
36 |
# File 'lib/uniword/assembly/toc_instruction.rb', line 36 attribute :separator, :string |
#to_s ⇒ String
Generate the field instruction string.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/uniword/assembly/toc_instruction.rb', line 47 def to_s parts = ["TOC"] parts << "\\o \"#{outline_levels}\"" if outline_levels parts << '\\h' if hyperlinks parts << '\\z' if hidden_formats parts << '\\u' if use_paragraph_outline parts << '\\w' if preserve_tabs parts << "\\s \"#{separator}\"" if separator parts << "\\l \"#{leader}\"" if leader parts.join(" ") end |
#use_paragraph_outline ⇒ Boolean
Returns Use paragraph outline level.
30 |
# File 'lib/uniword/assembly/toc_instruction.rb', line 30 attribute :use_paragraph_outline, :boolean, default: -> { true } |