Class: Ast::Merge::Text::WordNode
- Inherits:
-
Object
- Object
- Ast::Merge::Text::WordNode
- Defined in:
- lib/ast/merge/text/word_node.rb
Overview
Represents a word within a line of text. Words are the nested level of the text-based AST. They are identified by word boundaries (regex b).
Instance Attribute Summary collapse
-
#content ⇒ String
readonly
The word content.
-
#end_col ⇒ Integer
readonly
0-based ending column position (exclusive).
-
#line_number ⇒ Integer
readonly
1-based line number containing this word.
-
#start_col ⇒ Integer
readonly
0-based starting column position.
-
#word_index ⇒ Integer
readonly
0-based index of this word within the line.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check equality with another WordNode.
-
#hash ⇒ Integer
Hash code for use in Hash keys.
-
#initialize(content, line_number:, word_index:, start_col:, end_col:) ⇒ WordNode
constructor
Initialize a new WordNode.
-
#inspect ⇒ String
String representation for debugging.
-
#signature ⇒ Array
Generate a signature for this word node.
-
#to_s ⇒ String
Convert to string (returns content).
Constructor Details
#initialize(content, line_number:, word_index:, start_col:, end_col:) ⇒ WordNode
Initialize a new WordNode
37 38 39 40 41 42 43 |
# File 'lib/ast/merge/text/word_node.rb', line 37 def initialize(content, line_number:, word_index:, start_col:, end_col:) @content = content @line_number = line_number @word_index = word_index @start_col = start_col @end_col = end_col end |
Instance Attribute Details
#content ⇒ String (readonly)
Returns The word content.
16 17 18 |
# File 'lib/ast/merge/text/word_node.rb', line 16 def content @content end |
#end_col ⇒ Integer (readonly)
Returns 0-based ending column position (exclusive).
28 29 30 |
# File 'lib/ast/merge/text/word_node.rb', line 28 def end_col @end_col end |
#line_number ⇒ Integer (readonly)
Returns 1-based line number containing this word.
19 20 21 |
# File 'lib/ast/merge/text/word_node.rb', line 19 def line_number @line_number end |
#start_col ⇒ Integer (readonly)
Returns 0-based starting column position.
25 26 27 |
# File 'lib/ast/merge/text/word_node.rb', line 25 def start_col @start_col end |
#word_index ⇒ Integer (readonly)
Returns 0-based index of this word within the line.
22 23 24 |
# File 'lib/ast/merge/text/word_node.rb', line 22 def word_index @word_index end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check equality with another WordNode
57 58 59 |
# File 'lib/ast/merge/text/word_node.rb', line 57 def ==(other) other.is_a?(WordNode) && @content == other.content end |
#hash ⇒ Integer
Hash code for use in Hash keys
66 67 68 |
# File 'lib/ast/merge/text/word_node.rb', line 66 def hash @content.hash end |
#inspect ⇒ String
String representation for debugging
73 74 75 |
# File 'lib/ast/merge/text/word_node.rb', line 73 def inspect "#<WordNode #{@content.inspect} line=#{@line_number} col=#{@start_col}..#{@end_col}>" end |
#signature ⇒ Array
Generate a signature for this word node. The signature is used for matching words across template/destination.
49 50 51 |
# File 'lib/ast/merge/text/word_node.rb', line 49 def signature [:word, @content] end |
#to_s ⇒ String
Convert to string (returns content)
80 81 82 |
# File 'lib/ast/merge/text/word_node.rb', line 80 def to_s @content end |