Tranga-Website/Tranga/Chapter.cs

35 lines
1.3 KiB
C#
Raw Normal View History

2023-05-18 20:06:29 +02:00
using System.Globalization;
2023-05-25 16:55:58 +02:00
using System.Text.RegularExpressions;
2023-05-18 20:06:29 +02:00
namespace Tranga;
/// <summary>
/// Has to be Part of a publication
/// Includes the Chapter-Name, -VolumeNumber, -ChapterNumber, the location of the chapter on the internet and the saveName of the local file.
/// </summary>
public struct Chapter
{
public string? name { get; }
public string? volumeNumber { get; }
public string? chapterNumber { get; }
public string url { get; }
public string fileName { get; }
2023-05-20 02:39:23 +02:00
public string sortNumber { get; }
2023-05-25 16:55:58 +02:00
private static readonly Regex LegalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*~*!*)*");
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
{
this.name = name;
this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1";
this.chapterNumber = chapterNumber;
this.url = url;
2023-05-25 16:55:58 +02:00
string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
2023-05-20 02:10:10 +02:00
NumberFormatInfo nfi = new NumberFormatInfo()
{
NumberDecimalSeparator = "."
};
sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber) * Convert.ToDecimal(this.chapterNumber, nfi), 1)
2023-05-20 02:39:23 +02:00
.ToString(nfi);
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {sortNumber}";
}
}