Class: Ast::Merge::Text::Section

Inherits:
Struct
  • Object
show all
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).

Examples:

A Markdown section

Section.new(
  name: "Installation",
  header: "## Installation\n",
  body: "Install the gem...\n",
  start_line: 10,
  end_line: 25,
  metadata: { heading_level: 2 }
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



26
27
28
# File 'lib/ast/merge/text/section.rb', line 26

def body
  @body
end

#end_lineObject

Returns the value of attribute end_line

Returns:

  • (Object)

    the current value of end_line



26
27
28
# File 'lib/ast/merge/text/section.rb', line 26

def end_line
  @end_line
end

#headerObject

Returns the value of attribute header

Returns:

  • (Object)

    the current value of header



26
27
28
# File 'lib/ast/merge/text/section.rb', line 26

def header
  @header
end

#metadataObject

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



26
27
28
# File 'lib/ast/merge/text/section.rb', line 26

def 
  @metadata
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



26
27
28
# File 'lib/ast/merge/text/section.rb', line 26

def name
  @name
end

#start_lineObject

Returns the value of attribute start_line

Returns:

  • (Object)

    the current value of start_line



26
27
28
# File 'lib/ast/merge/text/section.rb', line 26

def start_line
  @start_line
end

Instance Method Details

#full_textString

Reconstructs the full section text including header.

Returns:

  • (String)

    The complete section with header and body



69
70
71
72
73
74
# File 'lib/ast/merge/text/section.rb', line 69

def full_text
  result = +''
  result << header.to_s if header
  result << body.to_s
  result
end

#line_countInteger?

Returns the number of lines this section spans.

Returns:

  • (Integer, nil)

    The number of lines



60
61
62
63
64
# File 'lib/ast/merge/text/section.rb', line 60

def line_count
  return unless start_line && end_line

  end_line - start_line + 1
end

#line_rangeRange?

Returns the line range covered by this section.

Returns:

  • (Range, nil)

    The range from start_line to end_line (inclusive)



51
52
53
54
55
# File 'lib/ast/merge/text/section.rb', line 51

def line_range
  return unless start_line && end_line

  start_line..end_line
end

#normalized_nameString

Normalize the section name for matching. Strips whitespace, downcases, and normalizes spaces.

Returns:

  • (String)

    Normalized name for matching



87
88
89
90
91
92
# File 'lib/ast/merge/text/section.rb', line 87

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).

Returns:

  • (Boolean)

    true if this is the preamble



79
80
81
# File 'lib/ast/merge/text/section.rb', line 79

def preamble?
  name == :preamble
end