0
0
RhSolutions-Api/RhSolutions.Parsers/DrinkingWaterHeatingPipes/DrinkingWaterHeatingPipe.cs
Serghei Cebotari d4a9149daa
All checks were successful
Test and release / test (push) Successful in 2m39s
Test and release / release-image (push) Successful in 4m26s
Return flex result for stabil pipe over 40 diameter
2024-02-16 14:18:49 +03:00

57 lines
1.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text.RegularExpressions;
namespace RhSolutions.Parsers.Pipes;
public abstract class DrinkingWaterHeatingPipe : IProductParser
{
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;
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"
};
protected virtual Dictionary<string, string> _makeUp { get; } = new()
{
["бухт"] = "бухта",
["штанг"] = "прям.отрезки",
["отр"] = "прям.отрезки"
};
public virtual bool TryParse(string input, out string output)
{
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;
}
}