0
0
RhSolutions-Api/RhSolutions.Parsers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs

57 lines
1.5 KiB
C#
Raw Normal View History

2023-10-13 15:04:27 +03:00
using System.Text.RegularExpressions;
2024-02-08 17:11:11 +03:00
namespace RhSolutions.Parsers.Pipes;
2023-10-13 15:04:27 +03:00
2024-02-08 17:11:11 +03:00
public abstract class DrinkingWaterHeatingPipe : IProductParser
2023-10-13 15:04:27 +03:00
{
2023-10-22 13:43:18 +03:00
protected static readonly Regex _diameter =
new(@"([\b\D]|^)?(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)");
protected static readonly Regex _type =
new(@"([\b\W])(?<Type>бухт|отр|штанг)([\b\w\.\s])");
protected virtual string _title { get; } = string.Empty;
2023-10-13 15:04:27 +03:00
2023-10-22 13:43:18 +03:00
protected virtual Dictionary<int, string> _diameterNames { get; } = new()
{
[16] = "16x2,2",
[20] = "20x2,8",
[25] = "25x3,5",
[32] = "32x4,4",
[40] = "40x5,5",
[50] = "50x6,9",
[63] = "63x8,6"
};
2023-10-13 15:04:27 +03:00
2023-10-22 13:43:18 +03:00
protected virtual Dictionary<string, string> _makeUp { get; } = new()
{
["бухт"] = "бухта",
["штанг"] = "прям.отрезки",
["отр"] = "прям.отрезки"
};
2023-10-13 15:04:27 +03:00
2024-02-08 17:11:11 +03:00
public bool TryParse(string input, out string output)
2023-10-20 22:35:44 +03:00
{
2023-10-22 13:43:18 +03:00
output = string.Empty;
var diameterMatch = _diameter.Match(input);
if (!diameterMatch.Success)
{
return false;
}
var diameter = int.Parse(diameterMatch.Groups["Diameter"].Value);
var typeMatch = _type.Match(input);
if (typeMatch.Success)
{
var type = typeMatch.Groups["Type"].Value;
output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp[type]}";
}
else if (diameter < 32)
{
output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp["бухт"]}";
}
else
{
output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp["отр"]}";
}
return true;
2023-10-20 22:35:44 +03:00
}
2023-10-13 15:04:27 +03:00
}