Class: Ast::Merge::Text::LineNode
- Inherits:
-
Object
- Object
- Ast::Merge::Text::LineNode
- Defined in:
- lib/ast/merge/text/line_node.rb
Overview
Represents a line of text in the text-based AST. Lines are top-level nodes, with words as nested children.
Instance Attribute Summary collapse
-
#content ⇒ String
readonly
The full line content (without trailing newline).
-
#line_number ⇒ Integer
readonly
1-based line number.
-
#words ⇒ Array<WordNode>
readonly
Words contained in this line.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check equality with another LineNode.
-
#blank? ⇒ Boolean
Check if this line is blank (empty or whitespace only).
-
#comment? ⇒ Boolean
Check if this line is a comment (starts with # after whitespace) This is a simple heuristic for text files.
-
#end_line ⇒ Integer
Get the ending line (for compatibility with AST node interface).
-
#hash ⇒ Integer
Hash code for use in Hash keys.
-
#initialize(content, line_number:) ⇒ LineNode
constructor
Initialize a new LineNode.
-
#inspect ⇒ String
String representation for debugging.
-
#normalized_content ⇒ String
Get normalized content (trimmed whitespace for comparison).
-
#signature ⇒ Array
Generate a signature for this line node.
-
#start_line ⇒ Integer
Get the starting line (for compatibility with AST node interface).
-
#to_s ⇒ String
Convert to string (returns content).
Constructor Details
#initialize(content, line_number:) ⇒ LineNode
Initialize a new LineNode
28 29 30 31 32 |
# File 'lib/ast/merge/text/line_node.rb', line 28 def initialize(content, line_number:) @content = content @line_number = line_number @words = parse_words end |
Instance Attribute Details
#content ⇒ String (readonly)
Returns The full line content (without trailing newline).
16 17 18 |
# File 'lib/ast/merge/text/line_node.rb', line 16 def content @content end |
#line_number ⇒ Integer (readonly)
Returns 1-based line number.
19 20 21 |
# File 'lib/ast/merge/text/line_node.rb', line 19 def line_number @line_number end |
#words ⇒ Array<WordNode> (readonly)
Returns Words contained in this line.
22 23 24 |
# File 'lib/ast/merge/text/line_node.rb', line 22 def words @words end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check equality with another LineNode
82 83 84 |
# File 'lib/ast/merge/text/line_node.rb', line 82 def ==(other) other.is_a?(LineNode) && @content == other.content end |
#blank? ⇒ Boolean
Check if this line is blank (empty or whitespace only)
52 53 54 |
# File 'lib/ast/merge/text/line_node.rb', line 52 def blank? @content.strip.empty? end |
#comment? ⇒ Boolean
Check if this line is a comment (starts with # after whitespace) This is a simple heuristic for text files.
60 61 62 |
# File 'lib/ast/merge/text/line_node.rb', line 60 def comment? @content.strip.start_with?("#") end |
#end_line ⇒ Integer
Get the ending line (for compatibility with AST node interface)
74 75 76 |
# File 'lib/ast/merge/text/line_node.rb', line 74 def end_line @line_number end |
#hash ⇒ Integer
Hash code for use in Hash keys
91 92 93 |
# File 'lib/ast/merge/text/line_node.rb', line 91 def hash @content.hash end |
#inspect ⇒ String
String representation for debugging
98 99 100 |
# File 'lib/ast/merge/text/line_node.rb', line 98 def inspect "#<LineNode line=#{@line_number} #{@content.inspect} words=#{@words.size}>" end |
#normalized_content ⇒ String
Get normalized content (trimmed whitespace for comparison)
45 46 47 |
# File 'lib/ast/merge/text/line_node.rb', line 45 def normalized_content @content.strip end |
#signature ⇒ Array
Generate a signature for this line node. The signature is used for matching lines across template/destination.
38 39 40 |
# File 'lib/ast/merge/text/line_node.rb', line 38 def signature [:line, normalized_content] end |
#start_line ⇒ Integer
Get the starting line (for compatibility with AST node interface)
67 68 69 |
# File 'lib/ast/merge/text/line_node.rb', line 67 def start_line @line_number end |
#to_s ⇒ String
Convert to string (returns content)
105 106 107 |
# File 'lib/ast/merge/text/line_node.rb', line 105 def to_s @content end |