Class: Ast::Merge::SectionTyping::Classifier Abstract
- Inherits:
-
Object
- Object
- Ast::Merge::SectionTyping::Classifier
- Defined in:
- lib/ast/merge/section_typing.rb
Overview
This class is abstract.
Subclass and implement #classify
Base class for AST-aware section classifiers.
Subclasses implement ‘classify(node)` to identify section boundaries and extract section names from AST nodes.
Direct Known Subclasses
Instance Method Summary collapse
-
#classifies?(node) ⇒ Boolean
Check if a node can be classified by this classifier.
-
#classify(node) ⇒ TypedSection?
abstract
Classify a single AST node.
-
#classify_all(children) ⇒ Array<TypedSection>
Classify all children of a parent node.
Instance Method Details
#classifies?(node) ⇒ Boolean
Check if a node can be classified by this classifier.
140 141 142 |
# File 'lib/ast/merge/section_typing.rb', line 140 def classifies?(node) !classify(node).nil? end |
#classify(node) ⇒ TypedSection?
This method is abstract.
Subclasses must implement this method
Classify a single AST node.
100 101 102 |
# File 'lib/ast/merge/section_typing.rb', line 100 def classify(node) raise NotImplementedError, "#{self.class}#classify must be implemented" end |
#classify_all(children) ⇒ Array<TypedSection>
Classify all children of a parent node.
Iterates through child nodes and classifies each, grouping consecutive unclassified nodes into preamble/interstitial sections.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ast/merge/section_typing.rb', line 111 def classify_all(children) sections = [] unclassified_buffer = [] children.each do |child| if (section = classify(child)) # Flush unclassified buffer as preamble/interstitial if unclassified_buffer.any? sections << build_unclassified_section(unclassified_buffer) unclassified_buffer = [] end sections << section else unclassified_buffer << child end end # Flush remaining unclassified nodes if unclassified_buffer.any? sections << build_unclassified_section(unclassified_buffer) end sections end |