Class: Ace::Search::Molecules::DwimAnalyzer

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (Boolean)


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

Parameters:

  • pattern (String)

    Search pattern

  • options (Hash) (defaults to: {})

    Search options

Returns:

  • (Symbol)

    :file, :content, or :hybrid



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, options = {})
  # Explicit flags override DWIM
  return :file if options[:files_only] || options[:type] == :file
  return :content if options[:content_only] || options[:type] == :content
  return :hybrid if options[: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

Returns:

  • (Boolean)


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