Class: Ace::Search::Molecules::DwimAnalyzer
- Inherits:
-
Object
- Object
- Ace::Search::Molecules::DwimAnalyzer
- Defined in:
- lib/ace/search/molecules/dwim_analyzer.rb
Overview
Do-What-I-Mean analyzer for intelligent search mode detection This is a molecule - composed operation using PatternAnalyzer atom
Instance Method Summary collapse
-
#content_search_suitable?(pattern) ⇒ Boolean
Check if pattern is suitable for content search.
-
#determine_mode(pattern, options = {}) ⇒ Symbol
Determine search mode based on pattern and options.
-
#file_search_suitable?(pattern) ⇒ Boolean
Check if pattern is suitable for file search.
-
#initialize(pattern_analyzer: Atoms::PatternAnalyzer) ⇒ DwimAnalyzer
constructor
A new instance of DwimAnalyzer.
Constructor Details
#initialize(pattern_analyzer: Atoms::PatternAnalyzer) ⇒ DwimAnalyzer
Returns a new instance of DwimAnalyzer.
9 10 11 |
# File 'lib/ace/search/molecules/dwim_analyzer.rb', line 9 def initialize(pattern_analyzer: Atoms::PatternAnalyzer) @pattern_analyzer = pattern_analyzer end |
Instance Method Details
#content_search_suitable?(pattern) ⇒ Boolean
Check if pattern is suitable for content search
45 46 47 48 |
# File 'lib/ace/search/molecules/dwim_analyzer.rb', line 45 def content_search_suitable?(pattern) analysis = @pattern_analyzer.analyze_pattern(pattern) [:content_regex, :literal, :hybrid].include?(analysis[:type]) end |
#determine_mode(pattern, options = {}) ⇒ Symbol
Determine search mode based on pattern and options
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ace/search/molecules/dwim_analyzer.rb', line 17 def determine_mode(pattern, = {}) # Explicit flags override DWIM return :file if [:files_only] || [:type] == :file return :content if [:content_only] || [:type] == :content return :hybrid if [:type] == :hybrid # Analyze pattern for DWIM mode analysis = @pattern_analyzer.analyze_pattern(pattern) case analysis[:type] when :file_glob :file when :content_regex, :literal :content when :hybrid :hybrid else :content # Default to content search end end |
#file_search_suitable?(pattern) ⇒ Boolean
Check if pattern is suitable for file search
39 40 41 42 |
# File 'lib/ace/search/molecules/dwim_analyzer.rb', line 39 def file_search_suitable?(pattern) analysis = @pattern_analyzer.analyze_pattern(pattern) analysis[:type] == :file_glob || analysis[:type] == :hybrid end |