Class: MitchAI::Analyzers::FileAnalyzer
- Inherits:
-
Object
- Object
- MitchAI::Analyzers::FileAnalyzer
- 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++', '.cc' => 'C++', '.cxx' => 'C++', '.h' => 'C/C++ Header', '.hpp' => 'C++ Header', '.cs' => 'C#', '.php' => 'PHP', '.go' => 'Go', '.rs' => 'Rust', '.ts' => 'TypeScript', '.jsx' => 'React JSX', '.tsx' => 'React TSX', '.swift' => 'Swift', '.kt' => 'Kotlin', '.scala' => 'Scala', '.sh' => 'Shell Script', '.bash' => 'Bash', '.zsh' => 'Zsh', '.sql' => 'SQL', '.yml' => 'YAML', '.yaml' => 'YAML', '.json' => 'JSON', '.xml' => 'XML', '.dart' => 'Dart', '.vue' => 'Vue.js', '.svelte' => 'Svelte' }
Instance Method Summary collapse
- #analyze ⇒ Object
-
#initialize(file_path) ⇒ FileAnalyzer
constructor
A new instance of FileAnalyzer.
Constructor Details
#initialize(file_path) ⇒ FileAnalyzer
Returns a new instance of FileAnalyzer.
43 44 45 46 |
# File 'lib/mitch_ai/analyzers/file_analyzer.rb', line 43 def initialize(file_path) @file_path = file_path @ai_provider = MitchAI::AIProviders::OpenAIProvider.new end |
Instance Method Details
#analyze ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mitch_ai/analyzers/file_analyzer.rb', line 48 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 |