Class: Ast::Merge::SectionTyping::CompositeClassifier
- Inherits:
-
Classifier
- Object
- Classifier
- Ast::Merge::SectionTyping::CompositeClassifier
- Defined in:
- lib/ast/merge/section_typing.rb
Overview
A composite classifier that tries multiple classifiers in order.
Useful when a file may contain multiple types of sections (e.g., both ‘appraise` blocks and `group` blocks).
Instance Attribute Summary collapse
-
#classifiers ⇒ Array<Classifier>
readonly
Classifiers to try in order.
Instance Method Summary collapse
-
#classify(node) ⇒ TypedSection?
Try each classifier until one matches.
-
#initialize(*classifiers) ⇒ CompositeClassifier
constructor
Initialize with multiple classifiers.
Methods inherited from Classifier
Constructor Details
#initialize(*classifiers) ⇒ CompositeClassifier
Initialize with multiple classifiers.
217 218 219 |
# File 'lib/ast/merge/section_typing.rb', line 217 def initialize(*classifiers) @classifiers = classifiers.flatten end |
Instance Attribute Details
#classifiers ⇒ Array<Classifier> (readonly)
Returns Classifiers to try in order.
212 213 214 |
# File 'lib/ast/merge/section_typing.rb', line 212 def classifiers @classifiers end |
Instance Method Details
#classify(node) ⇒ TypedSection?
Try each classifier until one matches.
225 226 227 228 229 230 231 232 |
# File 'lib/ast/merge/section_typing.rb', line 225 def classify(node) classifiers.each do |classifier| if (section = classifier.classify(node)) return section end end nil end |