in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/ruby/util/RubyAstParser.java [134:179]
private static List<RubyClass> parseWithRegex(String content) {
List<RubyClass> classes = new ArrayList<>();
String[] lines = content.split("\n");
RubyClass currentClass = null;
int lineNum = 0;
for (String line : lines) {
lineNum++;
// Match class definitions: class MyController < ApplicationController
if (line.trim().matches("^class\\s+[A-Z]\\w*.*")) {
String className = line.replaceAll("^\\s*class\\s+([A-Z]\\w*).*", "$1");
String superclass = "";
if (line.contains("<")) {
superclass = line.replaceAll(".*<\\s*([A-Z]\\w*).*", "$1");
}
if (currentClass != null) {
classes.add(currentClass);
}
currentClass = new RubyClass(className, superclass, new ArrayList<>(), new ArrayList<>(), lineNum);
}
// Match method definitions: def index
else if (line.trim().matches("^def\\s+\\w+.*") && currentClass != null) {
String methodName = line.replaceAll("^\\s*def\\s+(\\w+).*", "$1");
currentClass.methods.add(new RubyMethod(methodName, List.of(), lineNum));
}
// Match before_action calls
else if (line.trim().matches("^before_action\\s+:.*") && currentClass != null) {
String action = line.replaceAll("^\\s*before_action\\s+:(\\w+).*", "$1");
currentClass.beforeActions.add(action);
}
// Match end
else if (line.trim().equals("end") && currentClass != null) {
// Could be end of class or method - we'll add class on next class or EOF
}
}
// Add last class
if (currentClass != null) {
classes.add(currentClass);
}
return classes;
}