< Summary - Jellyfin

Information
Class: Emby.Naming.Video.CleanDateTimeParser
Assembly: Emby.Naming
File(s): /srv/git/jellyfin/Emby.Naming/Video/CleanDateTimeParser.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 55
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
Clean(...)100%66100%
TryClean(...)100%1010100%

File(s)

/srv/git/jellyfin/Emby.Naming/Video/CleanDateTimeParser.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Globalization;
 3using System.Text.RegularExpressions;
 4
 5namespace Emby.Naming.Video
 6{
 7    /// <summary>
 8    /// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
 9    /// </summary>
 10    public static class CleanDateTimeParser
 11    {
 12        /// <summary>
 13        /// Attempts to clean the name.
 14        /// </summary>
 15        /// <param name="name">Name of video.</param>
 16        /// <param name="cleanDateTimeRegexes">Optional list of regexes to clean the name.</param>
 17        /// <returns>Returns <see cref="CleanDateTimeResult"/> object.</returns>
 18        public static CleanDateTimeResult Clean(string name, IReadOnlyList<Regex> cleanDateTimeRegexes)
 19        {
 27120            CleanDateTimeResult result = new CleanDateTimeResult(name);
 27121            if (string.IsNullOrEmpty(name))
 22            {
 123                return result;
 24            }
 25
 27026            var len = cleanDateTimeRegexes.Count;
 121027            for (int i = 0; i < len; i++)
 28            {
 44129                if (TryClean(name, cleanDateTimeRegexes[i], ref result))
 30                {
 10631                    return result;
 32                }
 33            }
 34
 16435            return result;
 36        }
 37
 38        private static bool TryClean(string name, Regex expression, ref CleanDateTimeResult result)
 39        {
 44140            var match = expression.Match(name);
 41
 44142            if (match.Success
 44143                && match.Groups.Count == 5
 44144                && match.Groups[1].Success
 44145                && match.Groups[2].Success
 44146                && int.TryParse(match.Groups[2].ValueSpan, NumberStyles.Integer, CultureInfo.InvariantCulture, out var y
 47            {
 10648                result = new CleanDateTimeResult(match.Groups[1].Value.TrimEnd(), year);
 10649                return true;
 50            }
 51
 33552            return false;
 53        }
 54    }
 55}