2023-10-13 23:38:28 +03:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
2024-01-26 15:50:41 +03:00
|
|
|
namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
|
2023-10-13 23:38:28 +03:00
|
|
|
|
2024-01-26 15:50:41 +03:00
|
|
|
[MLModifierKey("Трубка Г-образная")]
|
2023-10-13 23:38:28 +03:00
|
|
|
public class ConnectionBend : DrinkingWaterHeatingFitting
|
|
|
|
{
|
2024-01-26 15:50:41 +03:00
|
|
|
private static readonly int[] lengths = [250, 500, 1000];
|
2023-10-13 23:38:28 +03:00
|
|
|
private static readonly Regex _pattern =
|
|
|
|
new(@"([\b\D]|^)?(?<Diameter>16|20|25)(\D+|.*15.*)(?<Length>\b\d{3,4})([\b\D]|$)");
|
|
|
|
protected override string _title => "Трубка Г-образная";
|
|
|
|
|
2023-10-22 13:43:18 +03:00
|
|
|
public override bool TryQueryModify(string input, out string output)
|
2023-10-13 23:38:28 +03:00
|
|
|
{
|
2023-10-22 13:43:18 +03:00
|
|
|
output = string.Empty;
|
|
|
|
var match = _pattern.Match(input);
|
2023-10-13 23:38:28 +03:00
|
|
|
if (!match.Success)
|
|
|
|
{
|
2023-10-22 13:43:18 +03:00
|
|
|
return false;
|
2023-10-13 23:38:28 +03:00
|
|
|
}
|
|
|
|
string diameter = match.Groups["Diameter"].Value;
|
|
|
|
int length = int.Parse(match.Groups["Length"].Value);
|
|
|
|
int nearest = lengths.OrderBy(x => Math.Abs(x - length)).First();
|
2023-10-22 13:43:18 +03:00
|
|
|
output = $"{_title} {diameter}/{nearest}";
|
|
|
|
return true;
|
2023-10-13 23:38:28 +03:00
|
|
|
}
|
|
|
|
}
|