Class: MitchAI::Analyzers::FileAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/mitch_ai/analyzers/file_analyzer.rb

Constant Summary collapse

LANGUAGE_MAP =

Simple mapping of file extensions to languages

{
  '.rb' => 'Ruby',
  '.py' => 'Python',
  '.js' => 'JavaScript',
  '.html' => 'HTML',
  '.css' => 'CSS',
  '.java' => 'Java',
  '.c' => 'C',
  '.cpp' => 'C++',
  '.php' => 'PHP',
  '.go' => 'Go',
  '.rs' => 'Rust',
  '.ts' => 'TypeScript',
  '.jsx' => 'React JSX',
  '.tsx' => 'React TSX',
}

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ FileAnalyzer

Returns a new instance of FileAnalyzer.



24
25
26
27
# File 'lib/mitch_ai/analyzers/file_analyzer.rb', line 24

def initialize(file_path)
  @file_path = file_path
  @ai_provider = MitchAI::AIProviders::OpenAIProvider.new
end

Instance Method Details

#analyzeObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mitch_ai/analyzers/file_analyzer.rb', line 29

def analyze
  # Read file contents
  code_content = File.read(@file_path)
  # Perform AI analysis
  ai_review = @ai_provider.analyze_code(code_content, language)

  # Construct result
  {
    file_path: @file_path,
    language: language,
    suggestions: parse_suggestions(ai_review[:suggestions])
  }
rescue Errno::ENOENT => e
  # Wrap the low-level error in a more user-friendly message
  raise "Error reading file: #{e.message}"
  
end