Some refactoring

This commit is contained in:
Deluan 2016-02-29 13:56:09 -05:00
parent 1c47b7b8ef
commit 1a4f783669
4 changed files with 19 additions and 24 deletions

View File

@ -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
}

View File

@ -1,7 +0,0 @@
package models
import "testing"
func TestEmpty(t *testing.T) {
}

View File

@ -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
}

17
utils/strings.go Normal file
View File

@ -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
}