From 1a4f783669f5c0a0031772ab9fc7a1c97e18e987 Mon Sep 17 00:00:00 2001 From: Deluan Date: Mon, 29 Feb 2016 13:56:09 -0500 Subject: [PATCH] Some refactoring --- models/artist.go | 16 ---------------- models/models_test.go | 7 ------- scanner/scanner.go | 3 ++- utils/strings.go | 17 +++++++++++++++++ 4 files changed, 19 insertions(+), 24 deletions(-) delete mode 100644 models/models_test.go create mode 100644 utils/strings.go diff --git a/models/artist.go b/models/artist.go index a1e3978a0..6e7570b12 100644 --- a/models/artist.go +++ b/models/artist.go @@ -1,23 +1,7 @@ package models -import ( - "strings" - "github.com/astaxie/beego" -) - type Artist struct { Id string Name string Albums map[string]bool -} - -func NoArticle(name string) string { - articles := strings.Split(beego.AppConfig.String("ignoredArticles"), " ") - for _, a := range articles { - n := strings.TrimPrefix(name, a + " ") - if (n != name) { - return n - } - } - return name } \ No newline at end of file diff --git a/models/models_test.go b/models/models_test.go deleted file mode 100644 index 75502dbd5..000000000 --- a/models/models_test.go +++ /dev/null @@ -1,7 +0,0 @@ -package models - -import "testing" - -func TestEmpty(t *testing.T) { - -} \ No newline at end of file diff --git a/scanner/scanner.go b/scanner/scanner.go index 26c396b50..373608840 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -5,6 +5,7 @@ import ( "github.com/deluan/gosonic/repositories" "github.com/deluan/gosonic/models" "strings" +"github.com/deluan/gosonic/utils" ) type Scanner interface { @@ -92,7 +93,7 @@ func persist(mfRepo *repositories.MediaFile, mf *models.MediaFile, albumRepo *re func collectIndex(a *models.Artist, artistIndex map[string]tempIndex) { name := a.Name - indexName := strings.ToLower(models.NoArticle(name)) + indexName := strings.ToLower(utils.NoArticle(name)) if indexName == "" { return } diff --git a/utils/strings.go b/utils/strings.go new file mode 100644 index 000000000..9c3eca8e8 --- /dev/null +++ b/utils/strings.go @@ -0,0 +1,17 @@ +package utils + +import ( + "strings" + "github.com/astaxie/beego" +) + +func NoArticle(name string) string { + articles := strings.Split(beego.AppConfig.String("ignoredArticles"), " ") + for _, a := range articles { + n := strings.TrimPrefix(name, a + " ") + if (n != name) { + return n + } + } + return name +}