Class: Ast::Merge::Text::Section
- Inherits:
-
Struct
- Object
- Struct
- Ast::Merge::Text::Section
- Defined in:
- lib/ast/merge/text/section.rb
Overview
Represents a named section within text content.
Sections are logical units of text that can be matched and merged independently. For example, in Markdown, sections might be delimited by headings; in plain text, sections might be delimited by comment markers.
This is used for text-based splitting of leaf node content, NOT for AST-level node classification (see SectionTyping for that).
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#end_line ⇒ Object
Returns the value of attribute end_line.
-
#header ⇒ Object
Returns the value of attribute header.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#start_line ⇒ Object
Returns the value of attribute start_line.
Instance Method Summary collapse
-
#full_text ⇒ String
Reconstructs the full section text including header.
-
#line_count ⇒ Integer?
Returns the number of lines this section spans.
-
#line_range ⇒ Range?
Returns the line range covered by this section.
-
#normalized_name ⇒ String
Normalize the section name for matching.
-
#preamble? ⇒ Boolean
Check if this is the preamble section (content before first split point).
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
26 27 28 |
# File 'lib/ast/merge/text/section.rb', line 26 def body @body end |
#end_line ⇒ Object
Returns the value of attribute end_line
26 27 28 |
# File 'lib/ast/merge/text/section.rb', line 26 def end_line @end_line end |
#header ⇒ Object
Returns the value of attribute header
26 27 28 |
# File 'lib/ast/merge/text/section.rb', line 26 def header @header end |
#metadata ⇒ Object
Returns the value of attribute metadata
26 27 28 |
# File 'lib/ast/merge/text/section.rb', line 26 def @metadata end |
#name ⇒ Object
Returns the value of attribute name
26 27 28 |
# File 'lib/ast/merge/text/section.rb', line 26 def name @name end |
#start_line ⇒ Object
Returns the value of attribute start_line
26 27 28 |
# File 'lib/ast/merge/text/section.rb', line 26 def start_line @start_line end |
Instance Method Details
#full_text ⇒ String
Reconstructs the full section text including header.
67 68 69 70 71 72 |
# File 'lib/ast/merge/text/section.rb', line 67 def full_text result = +"" result << header.to_s if header result << body.to_s result end |
#line_count ⇒ Integer?
Returns the number of lines this section spans.
59 60 61 62 |
# File 'lib/ast/merge/text/section.rb', line 59 def line_count return unless start_line && end_line end_line - start_line + 1 end |
#line_range ⇒ Range?
Returns the line range covered by this section.
51 52 53 54 |
# File 'lib/ast/merge/text/section.rb', line 51 def line_range return unless start_line && end_line start_line..end_line end |
#normalized_name ⇒ String
Normalize the section name for matching. Strips whitespace, downcases, and normalizes spaces.
85 86 87 88 89 |
# File 'lib/ast/merge/text/section.rb', line 85 def normalized_name return "" if name.nil? return name.to_s if name.is_a?(Symbol) name.to_s.strip.downcase.gsub(/\s+/, " ") end |
#preamble? ⇒ Boolean
Check if this is the preamble section (content before first split point).
77 78 79 |
# File 'lib/ast/merge/text/section.rb', line 77 def preamble? name == :preamble end |