< Summary

Information
Class: Chronicis.Client.Services.RenderDefinitionHelpers
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/RenderDefinitionHelpers.cs
Line coverage
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 68
Line coverage: 100%
Branch coverage
100%
Covered branches: 19
Total branches: 19
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
IsHiddenField(...)100%11100%
IsNullOrEmpty(...)100%1111100%
IsDescriptionField(...)100%22100%
FormatFieldName(...)100%11100%
FormatGroupLabel(...)100%44100%
StripPrefix(...)100%22100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/RenderDefinitionHelpers.cs

#LineLine coverage
 1using System.Collections.Frozen;
 2using System.Text.Json;
 3
 4namespace Chronicis.Client.Services;
 5
 6/// <summary>
 7/// Shared formatting and classification helpers for render definition generation.
 8/// </summary>
 9public static class RenderDefinitionHelpers
 10{
 111    private static readonly FrozenSet<string> HiddenFields =
 112        new HashSet<string>(StringComparer.OrdinalIgnoreCase)
 113        {
 114            "pk", "model", "document", "illustration", "url", "key", "slug",
 115            "hover", "v2_converted_path", "img_main", "document__slug",
 116            "document__title", "document__license_url", "document__url",
 117            "page_no", "spell_list", "environments"
 118        }.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
 19
 120    public static readonly string[] TitleCandidates = { "name", "title" };
 21
 122    public static readonly string[] AbilitySuffixes =
 123        { "strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma" };
 24
 125    public static readonly string[] AbilityLabels =
 126        { "STR", "DEX", "CON", "INT", "WIS", "CHA" };
 27
 5628    public static bool IsHiddenField(string name) => HiddenFields.Contains(name);
 29
 30    public static bool IsNullOrEmpty(JsonElement value)
 31    {
 13932        return value.ValueKind switch
 13933        {
 234            JsonValueKind.Null or JsonValueKind.Undefined => true,
 10735            JsonValueKind.String => string.IsNullOrWhiteSpace(value.GetString()) ||
 10736                                    value.GetString() == "—" || value.GetString() == "-",
 637            JsonValueKind.Array => value.GetArrayLength() == 0,
 2438            _ => false
 13939        };
 40    }
 41
 42    public static bool IsDescriptionField(string name) =>
 3143        name.Contains("description", StringComparison.OrdinalIgnoreCase) ||
 3144        name.Contains("desc", StringComparison.OrdinalIgnoreCase);
 45
 46    public static string FormatFieldName(string name)
 47    {
 7348        return string.Join(' ', name
 7349            .Split('_')
 7350            .Where(s => !string.IsNullOrEmpty(s))
 7351            .Select(s => char.ToUpperInvariant(s[0]) + s[1..]));
 52    }
 53
 54    public static string FormatGroupLabel(string prefix)
 55    {
 2556        var label = FormatFieldName(prefix);
 2557        if (!label.EndsWith('s') && !label.EndsWith("es"))
 2258            label += "s";
 2559        return label;
 60    }
 61
 62    public static string StripPrefix(string name, string prefix)
 63    {
 5464        if (name.StartsWith(prefix + "_", StringComparison.OrdinalIgnoreCase))
 5365            return name[(prefix.Length + 1)..];
 166        return name;
 67    }
 68}