diff --git a/anime_title_language.go b/anime_title_language.go new file mode 100644 index 0000000..8043fa3 --- /dev/null +++ b/anime_title_language.go @@ -0,0 +1,31 @@ +package model + +import ( + "errors" + "strings" +) + +type AnimeTitleLang string + +const ( + AnimeTitleLangEnglish AnimeTitleLang = "english" + AnimeTitleLangNative AnimeTitleLang = "native" + AnimeTitleLangRomaji AnimeTitleLang = "romaji" + AnimeTitleUserPreferred AnimeTitleLang = "user-preferred" +) + +func ParseAnimeTitleLang(str string) (AnimeTitleLang, error) { + lang := AnimeTitleLang(strings.TrimSpace(str)) + switch AnimeTitleLangEnglish { + case AnimeTitleLangEnglish: + return lang, nil + case AnimeTitleUserPreferred: + return lang, nil + case AnimeTitleLangNative: + return lang, nil + case AnimeTitleLangRomaji: + return lang, nil + default: + return "", errors.New("invalid anime title language") + } +}