Skip to content

Commit 20136d0

Browse files
committed
fix class name parsing
1 parent e698c42 commit 20136d0

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

class.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,22 @@ type Class struct {
1818
Repo string
1919
}
2020

21-
func (a *Class) MatchName(str string) bool {
22-
return a.Name == str || (strings.Contains(str, a.Name) && strings.Contains(str, "Object"))
21+
func (c *Class) MatchName(str string) bool {
22+
return c.Name == str || (strings.Contains(str, c.Name) && strings.Contains(str, "Object"))
2323
}
2424

25-
func (a *Class) MatchBuiltInMethods(str string) bool {
25+
func (c *Class) MatchBuiltInMethods(str string) bool {
2626
return strings.Contains(str, "builtin") && strings.Contains(str, "Methods")
2727
}
28+
29+
func (c *Class) SetClassname(filepath string) {
30+
split_path := strings.Split(filepath, "/")
31+
filename := split_path[len(split_path)-1]
32+
filename_no_ext := strings.Replace(filename, ".go", "", -1)
33+
34+
name := ""
35+
for _, segment := range strings.Split(filename_no_ext, "_") {
36+
name = name + strings.Title(segment)
37+
}
38+
c.Name = name
39+
}

parser.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ func ClassesFromDir(dir string) []Class {
3333
func classFromFile(filepath string) Class {
3434
allMethods := []Method{}
3535
class := Class{}
36-
37-
// Define class name
38-
split_path := strings.Split(filepath, "/")
39-
filename := split_path[len(split_path)-1]
40-
filename_no_ext := strings.Replace(filename, ".go", "", -1)
41-
class.Name = strings.Title(filename_no_ext)
36+
class.SetClassname(filepath)
4237

4338
// Parse target file
4439
fset := token.NewFileSet()

0 commit comments

Comments
 (0)