0
0
RhSolutions-Api/RhSolutions.Parsers/DrinkingWaterHeatingFittings/Adapter.cs

39 lines
835 B
C#
Raw Permalink 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.Fittings;
2023-10-13 15:04:27 +03:00
public abstract class Adapter : DrinkingWaterHeatingFitting
{
2024-02-19 22:13:08 +03:00
protected Dictionary<string, string> _defaultThreads = new()
{
["16"] = "1/2",
["20"] = "1/2",
["25"] = "3/4",
["32"] = "1",
["40"] = "1 1/4",
["50"] = "1 1/2",
["63"] = "2"
};
2024-02-08 17:11:11 +03:00
public override bool TryParse(string input, out string output)
2023-10-22 13:43:18 +03:00
{
output = string.Empty;
Match diameter = _diameter.Match(input);
2023-10-13 15:04:27 +03:00
if (!diameter.Success)
{
2023-10-22 13:43:18 +03:00
return false;
2023-10-13 15:04:27 +03:00
}
2023-10-22 13:43:18 +03:00
Match thread = _thread.Match(input);
2024-02-19 22:13:08 +03:00
string threadValue;
2023-10-13 15:04:27 +03:00
if (!thread.Success)
{
2024-02-19 22:13:08 +03:00
threadValue = _defaultThreads[diameter.Groups["Diameter"].Value];
}
else
{
threadValue = thread.Groups["Thread"].Value;
2023-10-13 15:04:27 +03:00
}
2024-02-19 22:13:08 +03:00
output = $"{_title} {diameter.Groups["Diameter"]} {threadValue}";
2023-10-22 13:43:18 +03:00
return true;
2023-10-13 15:04:27 +03:00
}
}