Skip to content

Commit ece7d7d

Browse files
unhappychoiceclaude
andcommitted
refactor: update extractor module integration
- Update mod.rs exports for new module structure - Refactor parser.rs to use CommonExtractor and registry - Update challenge_converter.rs to use Language methods - Reduce parser.rs from 1000+ lines to ~150 lines 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3840f61 commit ece7d7d

File tree

3 files changed

+15
-897
lines changed

3 files changed

+15
-897
lines changed

src/extractor/challenge_converter.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl ChallengeConverter {
1717

1818
pub fn convert_chunk_to_challenge(&self, chunk: CodeChunk) -> Challenge {
1919
let id = Uuid::new_v4().to_string();
20-
let language = self.language_to_string(&chunk.language);
20+
let language = chunk.language.to_string();
2121
let file_path = chunk.file_path.to_string_lossy().to_string();
2222

2323
Challenge::new(id, chunk.content)
@@ -84,7 +84,7 @@ impl ChallengeConverter {
8484
for file_path in file_paths {
8585
if let Ok(content) = std::fs::read_to_string(&file_path) {
8686
let id = Uuid::new_v4().to_string();
87-
let language = self.detect_language_from_path(&file_path);
87+
let language = super::Language::detect_from_path(&file_path);
8888
let file_path_str = file_path.to_string_lossy().to_string();
8989

9090
let line_count = content.lines().count();
@@ -100,18 +100,6 @@ impl ChallengeConverter {
100100
challenges
101101
}
102102

103-
fn detect_language_from_path(&self, path: &std::path::Path) -> String {
104-
match path.extension().and_then(|ext| ext.to_str()) {
105-
Some("rs") => "rust".to_string(),
106-
Some("ts") | Some("tsx") => "typescript".to_string(),
107-
Some("py") => "python".to_string(),
108-
Some("go") => "go".to_string(),
109-
Some("rb") => "ruby".to_string(),
110-
Some("js") | Some("jsx") => "javascript".to_string(),
111-
_ => "text".to_string(),
112-
}
113-
}
114-
115103
fn split_chunk_by_difficulty(
116104
&self,
117105
chunk: &CodeChunk,
@@ -177,7 +165,7 @@ impl ChallengeConverter {
177165
// Only create challenge if it meets minimum size for this difficulty
178166
if truncated_code_chars >= min_chars {
179167
let id = Uuid::new_v4().to_string();
180-
let language = self.language_to_string(&chunk.language);
168+
let language = chunk.language.to_string();
181169
let file_path = chunk.file_path.to_string_lossy().to_string();
182170

183171
let challenge = Challenge::new(id, truncated_content.to_string())
@@ -326,7 +314,7 @@ impl ChallengeConverter {
326314
for file_path in file_paths {
327315
if let Ok(content) = std::fs::read_to_string(&file_path) {
328316
let id = uuid::Uuid::new_v4().to_string();
329-
let language = self.detect_language_from_path(&file_path);
317+
let language = super::Language::detect_from_path(&file_path);
330318
let file_path_str = file_path.to_string_lossy().to_string();
331319

332320
let line_count = content.lines().count();
@@ -341,16 +329,4 @@ impl ChallengeConverter {
341329

342330
zen_challenges
343331
}
344-
345-
fn language_to_string(&self, language: &super::Language) -> String {
346-
match language {
347-
super::Language::Rust => "rust".to_string(),
348-
super::Language::TypeScript => "typescript".to_string(),
349-
super::Language::Python => "python".to_string(),
350-
super::Language::Ruby => "ruby".to_string(),
351-
super::Language::Go => "go".to_string(),
352-
super::Language::Swift => "swift".to_string(),
353-
super::Language::Kotlin => "kotlin".to_string(),
354-
}
355-
}
356332
}

src/extractor/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
pub mod centered_progress;
21
pub mod challenge_converter;
3-
pub mod chunk;
2+
pub mod core;
43
pub mod git_info;
5-
pub mod language;
4+
pub mod models;
65
pub mod parser;
6+
pub mod parsers;
77
pub mod progress;
88
pub mod repository_loader;
99

10-
pub use centered_progress::CenteredProgressReporter;
1110
pub use challenge_converter::ChallengeConverter;
12-
pub use chunk::{ChunkType, CodeChunk};
1311
pub use git_info::{GitInfoExtractor, GitRepositoryInfo};
14-
pub use language::Language;
15-
pub use parser::{CodeExtractor, ExtractionOptions};
12+
pub use models::{ChunkType, CodeChunk, ExtractionOptions, Language};
13+
pub use parser::CodeExtractor;
1614
pub use progress::{ConsoleProgressReporter, NoOpProgressReporter, ProgressReporter};
1715
pub use repository_loader::RepositoryLoader;

0 commit comments

Comments
 (0)