using System.Text.RegularExpressions; namespace RhSolutions.Parsers.Fittings; public abstract class Adapter : DrinkingWaterHeatingFitting { protected Dictionary _defaultThreads = new() { ["16"] = "1/2", ["20"] = "1/2", ["25"] = "3/4", ["32"] = "1", ["40"] = "1 1/4", ["50"] = "1 1/2", ["63"] = "2" }; public override bool TryParse(string input, out string output) { output = string.Empty; MatchCollection diameters = _diameter.Matches(input); if (diameters.Count < 1) { return false; } Match thread = _thread.Match(input); string threadValue; if (!thread.Success && diameters.Count >= 2) { var diameterThread = diameters[1].Groups["Diameter"]; threadValue = diameterThread.Value switch { "15" => "1/2", "20" => "3/4", "25" => "1", _ => string.Empty }; } else if (!thread.Success) { threadValue = _defaultThreads[diameters[0].Groups["Diameter"].Value]; } else { threadValue = thread.Groups["Thread"].Value; } output = $"{_title} {diameters[0].Groups["Diameter"]} {threadValue}"; return true; } }