< Summary - Jellyfin

Information
Class: Emby.Naming.Video.FileStackRule
Assembly: Emby.Naming
File(s): /srv/git/jellyfin/Emby.Naming/Video/FileStackRule.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 48
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
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%
Match(...)75%44100%

File(s)

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

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Text.RegularExpressions;
 3
 4namespace Emby.Naming.Video;
 5
 6/// <summary>
 7/// Regex based rule for file stacking (eg. disc1, disc2).
 8/// </summary>
 9public class FileStackRule
 10{
 11    private readonly Regex _tokenRegex;
 12
 13    /// <summary>
 14    /// Initializes a new instance of the <see cref="FileStackRule"/> class.
 15    /// </summary>
 16    /// <param name="token">Token.</param>
 17    /// <param name="isNumerical">Whether the file stack rule uses numerical or alphabetical numbering.</param>
 18    public FileStackRule(string token, bool isNumerical)
 19    {
 129020        _tokenRegex = new Regex(token, RegexOptions.IgnoreCase | RegexOptions.Compiled);
 21        IsNumerical = isNumerical;
 129022    }
 23
 24    /// <summary>
 25    /// Gets a value indicating whether the rule uses numerical or alphabetical numbering.
 26    /// </summary>
 27    public bool IsNumerical { get; }
 28
 29    /// <summary>
 30    /// Match the input against the rule regex.
 31    /// </summary>
 32    /// <param name="input">The input.</param>
 33    /// <param name="result">The part type and number or <c>null</c>.</param>
 34    /// <returns>A value indicating whether the input matched the rule.</returns>
 35    public bool Match(string input, [NotNullWhen(true)] out (string StackName, string PartType, string PartNumber)? resu
 36    {
 40737        result = null;
 40738        var match = _tokenRegex.Match(input);
 40739        if (!match.Success)
 40        {
 34341            return false;
 42        }
 43
 6444        var partType = match.Groups["parttype"].Success ? match.Groups["parttype"].Value : "unknown";
 6445        result = (match.Groups["filename"].Value, partType, match.Groups["number"].Value);
 6446        return true;
 47    }
 48}