Class: Ast::Merge::Detector::Region
- Inherits:
-
Struct
- Object
- Struct
- Ast::Merge::Detector::Region
- Defined in:
- lib/ast/merge/detector/base.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 contains the given line number.
-
#full_text ⇒ String
Reconstructs the full region text including delimiters.
-
#inspect ⇒ String
-
#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
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content
40 41 42 |
# File 'lib/ast/merge/detector/base.rb', line 40 def content @content end |
#delimiters ⇒ Object
Returns the value of attribute delimiters
40 41 42 |
# File 'lib/ast/merge/detector/base.rb', line 40 def delimiters @delimiters end |
#end_line ⇒ Object
Returns the value of attribute end_line
40 41 42 |
# File 'lib/ast/merge/detector/base.rb', line 40 def end_line @end_line end |
#metadata ⇒ Object
Returns the value of attribute metadata
40 41 42 |
# File 'lib/ast/merge/detector/base.rb', line 40 def @metadata end |
#start_line ⇒ Object
Returns the value of attribute start_line
40 41 42 |
# File 'lib/ast/merge/detector/base.rb', line 40 def start_line @start_line end |
#type ⇒ Object
Returns the value of attribute type
40 41 42 |
# File 'lib/ast/merge/detector/base.rb', line 40 def type @type end |
Instance Method Details
#contains_line?(line) ⇒ Boolean
Checks if this region contains the given line number.
85 86 87 |
# File 'lib/ast/merge/detector/base.rb', line 85 def contains_line?(line) line_range.cover?(line) end |
#full_text ⇒ String
Reconstructs the full region text including delimiters.
74 75 76 77 78 79 80 |
# File 'lib/ast/merge/detector/base.rb', line 74 def full_text return content if delimiters.nil? || delimiters.empty? opening = delimiters[0] || "" closing = delimiters[1] || "" "#{opening}\n#{content}#{closing}" end |
#inspect ⇒ String
104 105 106 107 108 109 110 111 |
# File 'lib/ast/merge/detector/base.rb', line 104 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/detector/base.rb', line 68 def line_count end_line - start_line + 1 end |
#line_range ⇒ Range
Returns the line range covered by this region.
62 63 64 |
# File 'lib/ast/merge/detector/base.rb', line 62 def line_range start_line..end_line end |
#overlaps?(other) ⇒ Boolean
Checks if this region overlaps with another region.
92 93 94 95 96 |
# File 'lib/ast/merge/detector/base.rb', line 92 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
99 100 101 |
# File 'lib/ast/merge/detector/base.rb', line 99 def to_s "Region<#{type}:#{start_line}-#{end_line}>" end |