Class: Ast::Merge::Region
- Inherits:
-
Struct
- Object
- Struct
- Ast::Merge::Region
- Defined in:
- lib/ast/merge/region.rb
Overview
Represents a detected region within a document.
Regions are portions of a document that can be handled by a specialized merger. For example, YAML frontmatter in a Markdown file, or a Ruby code block that should be merged using a Ruby-aware merger.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#delimiters ⇒ Object
Returns the value of attribute delimiters.
-
#end_line ⇒ Object
Returns the value of attribute end_line.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#start_line ⇒ Object
Returns the value of attribute start_line.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#contains_line?(line) ⇒ Boolean
Checks if this region overlaps with the given line number.
-
#full_text ⇒ String
Reconstructs the full region text including delimiters.
-
#inspect ⇒ String
Returns a detailed human-readable representation of the region.
-
#line_count ⇒ Integer
Returns the number of lines this region spans.
-
#line_range ⇒ Range
Returns the line range covered by this region.
-
#overlaps?(other) ⇒ Boolean
Checks if this region overlaps with another region.
-
#to_s ⇒ String
Returns a short string representation of the region.
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content
32 33 34 |
# File 'lib/ast/merge/region.rb', line 32 def content @content end |
#delimiters ⇒ Object
Returns the value of attribute delimiters
32 33 34 |
# File 'lib/ast/merge/region.rb', line 32 def delimiters @delimiters end |
#end_line ⇒ Object
Returns the value of attribute end_line
32 33 34 |
# File 'lib/ast/merge/region.rb', line 32 def end_line @end_line end |
#metadata ⇒ Object
Returns the value of attribute metadata
32 33 34 |
# File 'lib/ast/merge/region.rb', line 32 def end |
#start_line ⇒ Object
Returns the value of attribute start_line
32 33 34 |
# File 'lib/ast/merge/region.rb', line 32 def start_line @start_line end |
#type ⇒ Object
Returns the value of attribute type
32 33 34 |
# File 'lib/ast/merge/region.rb', line 32 def type @type end |
Instance Method Details
#contains_line?(line) ⇒ Boolean
Checks if this region overlaps with the given line number.
90 91 92 |
# File 'lib/ast/merge/region.rb', line 90 def contains_line?(line) line_range.cover?(line) end |
#full_text ⇒ String
Reconstructs the full region text including delimiters.
78 79 80 81 82 83 84 |
# File 'lib/ast/merge/region.rb', line 78 def full_text return content if delimiters.nil? || delimiters.empty? opening = delimiters[0] || "" closing = delimiters[1] || "" "#{opening}\n#{content}#{closing}" end |
#inspect ⇒ String
Returns a detailed human-readable representation of the region.
114 115 116 117 118 119 120 121 |
# File 'lib/ast/merge/region.rb', line 114 def inspect truncated = if content && content.length > 30 "#{content[0, 30]}..." else content.inspect end "#{self} #{truncated}" end |
#line_count ⇒ Integer
Returns the number of lines this region spans.
68 69 70 |
# File 'lib/ast/merge/region.rb', line 68 def line_count end_line - start_line + 1 end |
#line_range ⇒ Range
Returns the line range covered by this region.
59 60 61 |
# File 'lib/ast/merge/region.rb', line 59 def line_range start_line..end_line end |
#overlaps?(other) ⇒ Boolean
Checks if this region overlaps with another region.
98 99 100 101 102 |
# File 'lib/ast/merge/region.rb', line 98 def overlaps?(other) line_range.cover?(other.start_line) || line_range.cover?(other.end_line) || other.line_range.cover?(start_line) end |
#to_s ⇒ String
Returns a short string representation of the region.
107 108 109 |
# File 'lib/ast/merge/region.rb', line 107 def to_s "Region<#{type}:#{start_line}-#{end_line}>" end |