< Summary - Jellyfin

Information
Class: Emby.Naming.AudioBook.AudioBookNameParser
Assembly: Emby.Naming
File(s): /srv/git/jellyfin/Emby.Naming/AudioBook/AudioBookNameParser.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 67
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Parse(...)100%1616100%

File(s)

/srv/git/jellyfin/Emby.Naming/AudioBook/AudioBookNameParser.cs

#LineLine coverage
 1using System.Globalization;
 2using System.Text.RegularExpressions;
 3using Emby.Naming.Common;
 4
 5namespace Emby.Naming.AudioBook
 6{
 7    /// <summary>
 8    /// Helper class to retrieve name and year from audiobook previously retrieved name.
 9    /// </summary>
 10    public class AudioBookNameParser
 11    {
 12        private readonly NamingOptions _options;
 13
 14        /// <summary>
 15        /// Initializes a new instance of the <see cref="AudioBookNameParser"/> class.
 16        /// </summary>
 17        /// <param name="options">Naming options containing AudioBookNamesExpressions.</param>
 18        public AudioBookNameParser(NamingOptions options)
 19        {
 3520            _options = options;
 3521        }
 22
 23        /// <summary>
 24        /// Parse name and year from previously determined name of audiobook.
 25        /// </summary>
 26        /// <param name="name">Name of the audiobook.</param>
 27        /// <returns>Returns <see cref="AudioBookNameParserResult"/> object.</returns>
 28        public AudioBookNameParserResult Parse(string name)
 29        {
 3530            AudioBookNameParserResult result = default;
 21031            foreach (var expression in _options.AudioBookNamesExpressions)
 32            {
 7033                var match = Regex.Match(name, expression, RegexOptions.IgnoreCase);
 7034                if (match.Success)
 35                {
 3936                    if (result.Name is null)
 37                    {
 3438                        var value = match.Groups["name"];
 3439                        if (value.Success)
 40                        {
 3441                            result.Name = value.Value;
 42                        }
 43                    }
 44
 3945                    if (!result.Year.HasValue)
 46                    {
 3447                        var value = match.Groups["year"];
 3448                        if (value.Success)
 49                        {
 550                            if (int.TryParse(value.ValueSpan, NumberStyles.Integer, CultureInfo.InvariantCulture, out va
 51                            {
 552                                result.Year = intValue;
 53                            }
 54                        }
 55                    }
 56                }
 57            }
 58
 3559            if (string.IsNullOrEmpty(result.Name))
 60            {
 161                result.Name = name;
 62            }
 63
 3564            return result;
 65        }
 66    }
 67}